-
-
Notifications
You must be signed in to change notification settings - Fork 928
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
select value is not reflected if the list of options are loaded at a later time #2241
Comments
You can make it work with either:
const state = createMutable({
color: undefined, //undefined, so later it we can assign different value
options: [];
})
setTimeout(() => {
state.options.push(Color.Red)
state.options.push(Color.Blue)
state.color = Color.Blue
}, 1000)
return <select value={state.options.length && state.color} ... >
const state = createMutable({
colorIndex: 1,
options: [];
})
setTimeout(() => {
state.options = [Color.Red, Color.Blue]
}, 1000)
return <select value={state.options[state.colorIndex]} ... >
But I wonder if it's possible to make it work for your code |
@maciek50322 thank you for the detailed workarounds. Since this works automatically with Vue and React it would be nice to have one less gotcha for devs making the transition to Solid. |
We don't re-render like React or Vue so there has to be some level of different expectations here. My usual go to is how VanillaJS works. If you have a select that has a value and options are added later does it work? https://playground.solidjs.com/anonymous/70df1286-3b10-48c6-9b5a-c7c2ae93d018 There is a big difference to me between things that are conceptually synchronous not working as that makes no sense(order shouldn't be your concern), and things that happen asynchronously. I do think |
Interesting thing here is that it won't change even if you do select.value = Color.Red At the end, after adding options. I assumed solid does some custom magic for select value prop (similar to svg props), |
We don't use attributes for |
Something forgotten this days, is that you can just tell which value is selected when creating the options. |
Describe the bug
I am loading a list of select options from an API so the options get populated a bit after the element is rendered. The value of the select is already set but is not reflected after the list is loaded.
Your Example Website or App
https://playground.solidjs.com/anonymous/afff844c-d8cb-40ab-b368-7b0fe268ab6d
Steps to Reproduce the Bug or Issue
The text was updated successfully, but these errors were encountered: