diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 3c24df1084c..8e303ac0f1a 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -7136,12 +7136,36 @@ abstract class CommonObject var parent = $(this).find("option[parent]:first").attr("parent"); var infos = parent.split(":"); var parent_list = infos[0]; + + //Hide daughters lists + if ($("#"+child_list).val() == 0 && $("#"+parent_list).val() == 0){ + $("#"+child_list).hide(); + //Show mother lists + } else if ($("#"+parent_list).val() != 0){ + $("#"+parent_list).show(); + } + //Show the child list if the parent list value is selected + $("select[name=\""+parent_list+"\"]").click(function() { + if ($(this).val() != 0){ + $("#"+child_list).show() + } + }); + + //When we change parent list + $("select[name=\""+parent_list+"\"]").change(function() { + showOptions(child_list, parent_list, orig_select[child_list]); + //Select the value 0 on child list after a change on the parent list + $("#"+child_list).val(0).trigger("change"); + //Hide child lists if the parent value is set to 0 + if ($(this).val() == 0){ + $("#"+child_list).hide(); + } + $("select[name=\""+parent_list+"\"]").change(function() { showOptions(child_list, parent_list, orig_select[child_list]); }); }); } - setListDependencies(); }); '."\n";