Merge pull request #15372 from glu000/patch-1

Extrafields from type "select" depending on other fields not working in Safari & jquery select2 #15371
This commit is contained in:
Laurent Destailleur 2020-11-13 10:03:46 +01:00 committed by GitHub
commit 0d19d2d5e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6977,27 +6977,30 @@ abstract class CommonObject
$out .= ' $out .= '
<script> <script>
jQuery(document).ready(function() { jQuery(document).ready(function() {
function showOptions(child_list, parent_list) function showOptions(child_list, parent_list, orig_select)
{ {
var val = $("select[name=\""+parent_list+"\"]").val(); var val = $("select[name=\""+parent_list+"\"]").val();
var parentVal = parent_list + ":" + val; var parentVal = parent_list + ":" + val;
if(val > 0) { if(val > 0) {
$("select[name=\""+child_list+"\"] option[parent]").hide(); var options = orig_select.find("option[parent=\""+parentVal+"\"]").clone();
$("select[name=\""+child_list+"\"] option[parent=\""+parentVal+"\"]").show(); $("select[name=\""+child_list+"\"] option[parent]").remove();
$("select[name=\""+child_list+"\"]").append(options);
} else { } else {
$("select[name=\""+child_list+"\"] option").show(); var options = orig_select.find("option[parent]").clone();
$("select[name=\""+child_list+"\"] option[parent]").remove();
$("select[name=\""+child_list+"\"]").append(options);
} }
} }
function setListDependencies() { function setListDependencies() {
jQuery("select option[parent]").parent().each(function() { jQuery("select option[parent]").parent().each(function() {
var orig_select = {};
var child_list = $(this).attr("name"); var child_list = $(this).attr("name");
orig_select[child_list] = $(this).clone();
var parent = $(this).find("option[parent]:first").attr("parent"); var parent = $(this).find("option[parent]:first").attr("parent");
var infos = parent.split(":"); var infos = parent.split(":");
var parent_list = infos[0]; var parent_list = infos[0];
showOptions(child_list, parent_list);
$("select[name=\""+parent_list+"\"]").change(function() { $("select[name=\""+parent_list+"\"]").change(function() {
showOptions(child_list, parent_list); showOptions(child_list, parent_list, orig_select[child_list]);
}); });
}); });
} }