-
-
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 add attribute without a value using templates #301
Comments
I think the suggested way is two-way binding, but that's waiting on #10 |
In Svelte, the value of a boolean attribute like In other words, you can do this: <option value="a" selected="{{val == 'a'}}">a</option> Demo here — try changing the value in the JSON in the bottom right. (I also added two-way binding so that using the |
Awesome. Looks much nicer than that ternary. Thanks! This actually seems to work without including the selected attribute at all using only the binding: https://svelte.technology/repl/?version=1.6.11&gist=137e588f883100a9b50c8456d0df3ab3 Is that the best way to do it then? |
Oh I take it back, that only works when the value changes, not on the initial load hmm |
D'oh! Yes, I suppose it is 😀
Ooohhh... that's a bug. Will fix! |
Initialise <select> elements with two-way binding
This is fixed in 1.7.0. Thanks! |
👍 Thanks so much for the quick turnaround. Think the version needs to be updated in the |
It's a minor version, so it should be fine — rollup-plugin-svelte won't need to be updated until we reach version 2 (but you'd need to reinstall it to pick up the new version) |
It is entirely possible I am missing something very obvious, but I can’t seem to figure out how to render a
<select>
menu and add a selected attribute for the selected option.I tried using this but it gives a syntax error
https://svelte.technology/repl/?version=1.6.11&gist=dbf07e495a3c768a89a6de924c44ead9
I also tried using a ternary as described in #259, but that too gives a syntax error
The only way I could get it to work was doing this:
https://svelte.technology/repl/?version=1.6.11&gist=4c44e8756ae112646cc1150077a555d0
That is not ideal because it generates a bunch of unnecessary code to have to repeat the
selected=
for every option even if they are not selected (although I suppose gzip will take care of some of that).Is there a recommended/better way to do this?
Thanks so much!
The text was updated successfully, but these errors were encountered: