Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Selecting the preselected Options by complete label instead of short_lab... #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions lib/js/jquery.select-hierarchy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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++;
Expand Down