Replies: 2 comments 3 replies
-
It's a common mistake to try to bind |
Beta Was this translation helpful? Give feedback.
2 replies
-
is there a way to dynamically add bindings depending on input type? Input component i would like to use, excerpt, <script module lang="ts">
type Props = {
type?: 'checkbox' | 'text' | 'file'
value?: string | number | null
checked?: boolean | null
files?: File[] | null
}
</script>
<script lang="ts">
const {
type,
value: $bindable(),
checked: $bindable(),
files: $bindable(),
} = $props()
</script>
<input
bind:value={type !== 'file' && type !== 'checkbox' ? value : null}
bind:checked={type === 'checkbox' ? value : null}
bind:files={type === 'file' ? value : null}
/> edit: |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
In Svelte, if you try to bind the value of a checkbox input, you get an error. Why is this? If I remember correctly, a checkbox's values are either "on" or its original value. I know this wouldn't be used often (if at all) but why is Svelte so strict about checkbox values being bound that there's an error code dedicated to it?
Beta Was this translation helpful? Give feedback.
All reactions