In lang_dropdown.js in the DDSlick implementation (~line 43) it sets a data value to 0 when setting up the dropdown, In DDSelect's onSelected handler it checks this value and only redirects if the value is not empty, it then sets the value to 1.
else if (msddSettings.widget == "ddslick") {
$.data(document.body, 'ddslick'+key+'flag', 0);
select.ddslick({
width: msddSettings.width,
height: (msddSettings.height == 0) ? null : msddSettings.height,
showSelectedHTML: Boolean(msddSettings.showSelectedHTML),
imagePosition: msddSettings.imagePosition,
onSelected: function(data) {
var i = $.data(document.body, 'ddslick'+key+'flag');
if (i) {
$.data(document.body, 'ddslick'+key+'flag', 0);
var lang = data.selectedData.value;
var href = $('#lang-dropdown-select-'+key).parents('form').find('input[name="' + lang + '"]').val();
window.location.href = href;
}
$.data(document.body, 'ddslick'+key+'flag', 1);
}
});
}
Presumably this is because the onSelected method gets triggered once in the setup process and we don't want that to cause a redirect.
However if the behavior ever gets run again then the line where the value gets set to 0 runs again, but this doesn't trigger an additional call to the onSelected callback. Therefore the next time someone tries to change change the select value the value is empty and there's no redirect.
I thought of just adding a condition around $.data(document.body, 'ddslick'+key+'flag', 0);
so that it only sets the value to 0 if there isn't already a value, but ultimately it should probably be forcing the setup of the dropdowns to only happen once so wrapping most of the code in a .once()
seems sensible.
patch to follow
Comment | File | Size | Author |
---|---|---|---|
#2 | lang_dropdown-apply-js-once--ignore-whitespace.patch | 2.44 KB | PQ |
#1 | lang_dropdown-apply-js-once-2413129-1-D7.patch | 4.99 KB | PQ |
Comments
Comment #1
PQ CreditAttribution: PQ commentedPatch attached
Comment #2
PQ CreditAttribution: PQ commentedI've attached a copy of the patch created with -w (ignore whitespace) so it's a lot easier to see what's actually changed.
Comment #3
Rajab Natshah CreditAttribution: Rajab Natshah commentedComment #4
kala4ekComment #5
kala4ekFixed during #1699776: When using views ajax or other ajax the dropdown crashes
Comment #6
PQ CreditAttribution: PQ commentedExcellent to hear that this is in. Is there any chance of a retrospective credit on the other issue? I don't know if that's something that's possible to do.