-
Notifications
You must be signed in to change notification settings - Fork 25
Initial selected options in select-pure[multiple] not set #41
Comments
Thanks for the report! The problem was with multiple hidden inputs inside the form. It should be fixed in |
@dudyn5ky1 Thanks for your quick reply and fix. Using Should |
@dudyn5ky1 I currently work around this with a JS fix, but do you agree the issue is not resolved with the Alpha release? |
@davidhund sure thing, sorry for the delay. I'd be happy to review your PR |
@dudyn5ky1 Apologies if I was not clear: I've not made a change/workaround in your code, but created a very crude hotfix in my (extra) page's JS that simply sets the hidden inputs /**
* FIXME: WORKAROUND
* for https://github.com/dudyn5ky1/select-pure/issues/41
*
* At DOMReady: loop over `option-pure[selected]` items
* and add them to `value` of hidden input by that name
*/
document.addEventListener('DOMContentLoaded', (_event) => {
$$('select-pure').forEach(s => {
const _n = s.getAttribute('name');
const _o = s.selectedOptions;
if (_n && _o) {
const _i = $(`input[type="hidden"][name="${_n}"]`);
if (_i && !_i.value) {
_i.value = Array.from(_o).map(o=>o.value).join(',');
}
}
});
}); Again: this is not ideal, very crude, but seems to fix the issue. (I could take a look and properly try to address this with a PR) |
@davidhund yeah, definitely, you are correct. Will take a look at how to fix this soon. |
I've just encountered the opposite, whereby the To me, this is counter intuitive. The change event should only happen then the select box value has... changed. Should there not be a different event ('initialised'?) for once the select box has been initialised? |
I have a Vanilla
select-pure[multiple]
with oneoption[selected]
in aform
.The selected option is correctly shown as selected in the widget and it is present in
_selectedOptions
.However: the hidden input does not reflect this! It's value remains empty until I make another selection...
So submitting the form directly — without interacting with the select-pure element — does not correctly post my intially selection option(s). Only after (de)selecting another option is my initial
selected
option added to the hidden input...I believe the issue is that the method
updateHiddenInputInForm()
is only called bysetSelectValue()
which is only called on update, not initially. Unless I'm missing something?The text was updated successfully, but these errors were encountered: