What is the way in Svelte to get the Controlled Inputs behaviour (like in React).
I tried to prevent default checkbox behaviour on input click (prevents HTML checkbox to modify the checked prop).
<input
type=checkbox
bind:checked={done}
on:click|preventDefault={() => dispatch('change'}}
/>
But apparently, it does something else - and svelte bindings stoped working.
Tried without bind:checked
=> just checked={done}
- no results as well.
At the end I figured to do one-way binding via if
:
{#if done}
<input type=checkbox checked readonly />
{:else}
<input type=checkbox readonly />
{/if}
but that looks lame.
What is the proper way to implement Controlled Inputs
in Svelte?
Full simplified example you could find here: https://svelte.dev/repl/ecc812d1be34464185739f02ca2421cd?version=3.19.2