-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Unable to populate <select> default value to object during initial load #8238
Comments
These are different objects, fix: let selected = questions[0]; alternatively use |
Looks like the same issue as #8240. I.e. your code works the way you expect if you use svelte version 3.35.0. |
We need to get and save the whole object, not just a plain id. lookupData = differentTableQuery() it's so much hassle if we need to additional logic just to remap to the right value on client side. |
Where hassle? https://svelte.dev/repl/80081a1cbd8242d39249f3dafbd8b041?version=3.55.1 |
This is entirely different. It just looks like it's working, because the selected item happens to be the first one. Set it to anything else and the first one is still selected. |
@Prinzhorn
I need the 'selected' to bind to object not just a plain string/number, like what you share. But the issue comes, when I need this select to be populated with initial value which is a object, it's showing as empty. |
I understand that you want that, but Svelte can't deep compare the object to make that magically work. Even if it would, then this will break if your two sources of truth change (e.g. you change the question text slightly in the questions DB, but not in the "selected" DB). If you want to keep using objects, you must go through some hassle. Depending on how exactly your code works you can potentially easily abstract this to find the appropriate matching object. https://svelte.dev/repl/59f17560a366484289a4b51c53919b12?version=3.55.1 |
If there's change two sources, then it should show as empty (nothing selected). Would be great if svelte implement the default object equality, e.g: comparing all attributes, and allow user to extend them as needed |
@wngasinur,
That way, you're comparing the same object. |
ok, closing the issue, as it seems the best way to handle this is to use
|
I've select input bind to object, but I'm unable to populate the selected value when the screen is loaded for the first time.
Current behavior: the select is populated as empty
Expected behavior: the select should be populated with selected value/text
Reproduction
n/a
Logs
No response
System Info
Severity
annoyance
The text was updated successfully, but these errors were encountered: