terminal42 / contao-conditionalselectmenu

A Contao select menu widget which display options conditionally depending on another (conditional) select menu.
MIT License
6 stars 5 forks source link

Firefox default value issue #6

Closed qzminski closed 5 years ago

qzminski commented 9 years ago

When the condition field is changed and the new options are generated, the conditional field in Firefox takes the value of the first non empty option and thus it is selected by default.

Any ideas how to fix that?

https://github.com/terminal42/contao-conditionalselectmenu/blob/master/assets/conditionalselect.js#L105

// Chrome, Safari
console.log(element.value); // ""

// Firefox
console.log(element.value); // "4"
aschempp commented 7 years ago

I've tested this and cannot reproduce in the latest Firefox.

aschempp commented 5 years ago

I have this issue now as well. Firefox and Chrome select the first value even though there is an empty option. Safari works correctly.

richardhj commented 5 years ago

That's a tough one. I guess Safari and Chrome differ in how to they internally process the DOM change and how/when element.value can be accessed. I guess, in Safari element.value longer stays "" before it changes to the actual value, e.g. DE-BW. WDYT of 353f0c9?

aschempp commented 5 years ago

Looks good. Just a quick guess: If we do not have a default option, we still want the first option to be selected (or the browser will select it anyway), right? So maybe we don't need that check at all? I guess the idea of if (element.value) was to not change the current value if an option with the same value existed. But if we shuffle the options, we might as well reset the value?

richardhj commented 5 years ago

If we remove the block if (!element.value), the first option will always be selected, even if one option should be selected per default (see lines 24f.). So the current behavior should be: If default option available, it will be selected (lines 24ff), if not, the first one (may be the blank option) will be selected (lines 105ff). What do you mean by shuffling the options?

aschempp commented 5 years ago

Ah I see. So maybe the variable should rather be selectDefaultOption?

richardhj commented 5 years ago

I'll rename. How to minify the js?

aschempp commented 5 years ago

Looks like theres nothing in place to minify, I guess I just used any online or CLI tool back in the days. Feel free to use any dirty way. For new extensions that is Contao 4 only, I would use Webpack, but that does not make sense here as we don't have an src folder etc.