diff --git a/htdocs/core/js/lib_head.js.php b/htdocs/core/js/lib_head.js.php
index f75018fbdaf..a4df9ad3389 100644
--- a/htdocs/core/js/lib_head.js.php
+++ b/htdocs/core/js/lib_head.js.php
@@ -1173,4 +1173,39 @@ $(document).ready(function() {
}
});
+
+// Code to manage the js for combo list with dependencies (called by extrafields_view.tpl.php)
+function showOptions(child_list, parent_list) {
+ var parentInput = $("select[name="+parent_list+"]");
+ if (parentInput.length === 0) { // when parent extra-field is in view mode and the child is edited directly on card (on line edit)
+ parentInput = $("input[name="+parent_list+"]");
+ }
+ if (parentInput.length > 0) {
+ var val = parentInput.val();
+ var parentVal = parent_list + ":" + val;
+ if (val > 0) {
+ $("select[name=\""+child_list+"\"] option[parent]").prop("disabled", true).hide(); // hide not work with select2 element so disabled it
+ $("select[name=\""+child_list+"\"] option[parent=\""+parentVal+"\"]").prop('disabled', false).show(); // show not work with select2 element so enabled it
+ } else {
+ $("select[name=\""+child_list+"\"] option").prop("disabled", false).show(); // show not work with select2 element so enabled it
+ }
+ }
+}
+function setListDependencies() {
+ console.log("setListDependencies");
+ jQuery("select option[parent]").parent().each(function() {
+ var child_list = $(this).attr("name");
+ var parent = $(this).find("option[parent]:first").attr("parent");
+ var infos = parent.split(":");
+ var parent_list = infos[0];
+ showOptions(child_list, parent_list);
+
+ /* Activate the handler to call showOptions on each future change */
+ $("select[name=\""+parent_list+"\"]").change(function() {
+ showOptions(child_list, parent_list);
+ });
+ });
+}
+
+
// End of lib_head.js.php
diff --git a/htdocs/core/tpl/extrafields_view.tpl.php b/htdocs/core/tpl/extrafields_view.tpl.php
index cc0ee2b0f93..a328c9fe610 100644
--- a/htdocs/core/tpl/extrafields_view.tpl.php
+++ b/htdocs/core/tpl/extrafields_view.tpl.php
@@ -257,6 +257,7 @@ if (empty($reshook) && isset($extrafields->attributes[$object->table_element]['l
} else {
//var_dump($tmpkeyextra.'-'.$value.'-'.$object->table_element);
print $extrafields->showOutputField($tmpkeyextra, $value, '', $object->table_element);
+ print ''; // it's needed when to get parent value when extra-field list depend on parent extra-field list
}
print '';
@@ -271,31 +272,6 @@ if (empty($reshook) && isset($extrafields->attributes[$object->table_element]['l
print '
'."\n";