-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Two-way binding select does not allow for dynamic multiple attribute #1270
Comments
Thanks — opened #1313. Things get complex fast if you allow |
Thanks for your response. These kind of details have the tendency to be much harder to implement than just a simple workaround. A compiler error will help users to catch on to what is happening. |
fail validation if bound <select> has dynamic multiple attribute
Released 1.60.2 with this change |
2023...just ran across this. Thought I'd post that @Rich-Harris point to use if statement is still best path as near as I can tell. If you use |
Using Svelte 4.2.18 I did it like this: inside my script block: export let multiple: boolean;
export let ref: HTMLSelectElement;
$: {
if (multiple) {
ref && ref.setAttribute('multiple', '');
} else {
ref && ref.removeAttribute('multiple');
}
} inside the markup section <select bind:this="{ref}" bind:value="{value}">
...
</select> ...which is exactly what I would have Svelte expected to do. And I don't get why it doesn't and comes up with a compiler error instead, but this is my workaround. Maybe it is of some use for someone else. |
The two-way binding on multiple select elements don't take a dynamically set
multiple
-attribute into consideration.Maybe this is as intended, in which case it appears to be missing from the documentation (or I simply overlooked it).
A simple REPL to demonstrate the behavior.
Short examples:
<select bind:value multiple>
<select bind:value :multiple>
<select bind:value multiple="{{ multiple }}">
As for browsers, the behavior is consistent across browsers, tested in Firefox 60, Brave 0.21, Electron 1.8.3 (Chromium 59)
The text was updated successfully, but these errors were encountered: