From c61d90ded8837961fccb2f5b70c48fa5531b5b85 Mon Sep 17 00:00:00 2001 From: Christopher Kramer Date: Thu, 23 Apr 2015 17:41:11 +0200 Subject: [PATCH] Selecting the preselected Options by complete label instead of short_label. Otherwise it does not work if multiple options have the same short_label. --- lib/js/jquery.select-hierarchy.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/js/jquery.select-hierarchy.js b/lib/js/jquery.select-hierarchy.js index a073ec8..aad7da0 100644 --- a/lib/js/jquery.select-hierarchy.js +++ b/lib/js/jquery.select-hierarchy.js @@ -117,10 +117,10 @@ // After setting up the behavior, set the drilldown select lists to the correct values for // forms with a default value. - // Build an object of the choices keyed by short_label. - var choices_by_short_label = {}; + // Build an object of the choices keyed by label. + var choices_by_label = {}; $.each(choices, function() { - choices_by_short_label[(this).short_label] = (this); + choices_by_label[(this).label] = (this); }); // Break selected label into segments/short_labels @@ -130,9 +130,11 @@ // Loop over the segments of the selected value and select the appropriate values on the // drilldown select lists. var counter = 1; + var label = ""; $.each(segments, function() { - if(choices_by_short_label[(this)]) { - $('select.drilldown-' + counter, obj.parent()).val(choices_by_short_label[(this)].value); + label += (label=="" ? "" : options.separator) +(this); + if(choices_by_label[label]) { + $('select.drilldown-' + counter, obj.parent()).val(choices_by_label[label].value); $('select.drilldown-' + counter, obj.parent()).change(); } counter++;