https://github.com/sveltejs/svelte/pull/3527#issuecomment-534531584
Is your feature request related to a problem? Please describe.
Date inputs have string bindings, which are rarely helpful.
Describe the solution you'd like
It should be possible to specify the type of binding:
<input type="date" bind:value|date={date_as_date}>
<input type="date" bind:value|number={date_as_number}>
<input type="date" bind:value|string={date_as_string}>
In v4, we can switch the default over to the value|date behaviour.
Describe alternatives you've considered
Adding valueAsNumber and valueAsDate bindings. There are a couple of reasons not to do this:
number and range inputs are currently handledvalueAsNumber instead of just value. It's unergonomicHow important is this feature to you?
Medium
Might it be nice to add |number and |string to type='number' as well?
Would be good for <select> which doesn't have a type attribute.
I still would prefer bind : valueAsDate/valueAsNumber
I also like bind:value|date syntax, as I think it's a lot cleaner than the messy API exposed by browsers.
Is there a workaround for now?
@cupcakearmy
<input type="date" bind:value={date}>
$: dateAsDate= date && new Date(...date.split('-'))
@antony Thanks for the answer, but I needed 2 way binding.
Got it working though :)
https://svelte.dev/repl/dc963bbead384b69aad17824149d6d27?version=3.25.1
Most helpful comment
Might it be nice to add
|numberand|stringtotype='number'as well?