-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue when setting option values via function #52
Comments
Thanks for the catch @MasterPuffin. Please try v11.0.3 - it must be fixed there. Unfortunately I cannot see more reliable workaround than mutation observer. It's specific case of selects - they automatically change own value if children added/changed/removed, and no Watch out: state gets updated in a tick. |
The issue is fixed wirh 11.0.3.
It has to be this complex, because, as you mentioned, the update happens after one tick. |
Have you tried without delay @MasterPuffin ? It should not force you to do that, it should just work. |
I just tested it again to make sure, but without the delay it doesn't work for me. |
Hmm, that's not a way to go. Is that the test-case above? Would you be able to write basic example when it fails? I will try to make it sync if that's indeed the cause. |
I managed to reproduce the issue in a test case
I use the latest sprae.umd.min.js without any other code, if that matters. |
Can you elaborate this part: if (!object.defaultmode) {
(async () => {
await new Promise(resolve => setTimeout(resolve, 0));
state.object.defaultmode = null
})();
} What are you trying to achieve/test here? Normally it's supposed Also - I've updated to v11.0.4 with better mutation observer init order, IDK if it will make difference but you can test. |
Sorry for the late reply.
However the following code should also work to reset the selected option back to null. This is not the case.
|
What I can see in reproduction, both your snippets work identical on my side, there's no need for async wrapper. Please tell me if I understand your issue right. If we don't have this guard condition: if (!state.object.defaultmode) state.object.defaultmode = null then when you toggle/remove an item from the options list, it automatically selects the first available option, even if that was selection was null (unselected). So you would prefer to keep selected item empty when we modify options, right? In other words, you don't want to have this line |
Yes, that's exactly what I'm trying to achieve, when no option is selected, after adding or removing items, there should be still no option selected. |
So it means preserving selected option if list of options changes, even if new list doesn't include that. By default HTMLSelect selects first available option whenever it's available. Right now we follow that behaviour: when you add an option, select goes from null to first option. When you delete an option, select goes to next available option. When you delete all options it resets selection to null. It seems risky to attempt to rewrite default HTML behaviour. I think what you're doing with Please reopen if you find it an issue. |
Hello,
I found another issue:
I have an object where I use one value for a select field. When the value is set to null and initializing sprae, the dropdown is empty. When I now set the available values to an empty array and then push entries to the available values via a function, now the dropdown has selected a value. However if I now read from the original object the value set by the dropdown is still null.
Please see the following example code to reproduce this issue
The text was updated successfully, but these errors were encountered: