Skip to content
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

bind:value for keyed select tag doesn't work when options are updated #1764

Closed
aubergene opened this issue Oct 2, 2018 · 8 comments · Fixed by #4885
Closed

bind:value for keyed select tag doesn't work when options are updated #1764

aubergene opened this issue Oct 2, 2018 · 8 comments · Fixed by #4885
Labels

Comments

@aubergene
Copy link

The selected value is known oncreate, but the <option> values are added later. The selected value isn't set when they are added.

https://svelte.technology/repl?version=2.13.5&gist=17b698af0622793d4ab86ae62e275a51

Looks like it's related/similar to #1730 #1252 #1711

@stalkerg
Copy link
Contributor

yep, it's definitely my #1730 case.

@aubergene
Copy link
Author

aubergene commented Oct 23, 2018

As a horrid hack I've got this, any improvements most welcome

edit: solution below is much better, thanks!

@PaulMaly
Copy link
Contributor

@aubergene Hi! A quick workaround for this issue:
https://svelte.technology/repl?version=2.13.5&gist=4f15953652df80e9924a652e8865c8cd

<option selected={selected === item.slug} value="{item.slug}">{item.name}</option>

@Conduitry Conduitry added the bug label Oct 26, 2018
@Rich-Harris
Copy link
Member

Updated REPL for v3 (still broken) https://svelte.dev/repl/2c67955263d74afaa639dc4ef4c9fe2c?version=3.6.2

@stalkerg
Copy link
Contributor

stalkerg commented Aug 9, 2019

I also update my example to v3: https://svelte.dev/repl/a2e1ae9fd08640d494b892a135df3c8f?version=3

@Rich-Harris maybe you know, have any chance to change browser API here?

@Conduitry
Copy link
Member

At the same time as fixing this, we should also make it a compile-time error to specify selected on an <option> inside a <select> that is one- or two-way bound. That will unfortunately mean that the necessary workaround would then refuse to compile, but it seems like the sanest way to maintain a consistent state.

@adamduncan
Copy link

Hello 👋 Is there any update on this issue, or possible v3 workarounds in the interim?

@Conduitry
Copy link
Member

This is fixed at last in 3.23.0 - https://svelte.dev/repl/2c67955263d74afaa639dc4ef4c9fe2c?version=3.23.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants