Skip to content
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

bind:valueAsDate #3399

Closed
Rich-Harris opened this issue Aug 12, 2019 · 3 comments
Closed

bind:valueAsDate #3399

Rich-Harris opened this issue Aug 12, 2019 · 3 comments

Comments

@Rich-Harris
Copy link
Member

Is your feature request related to a problem? Please describe.

date inputs are a bit awkward to deal with since their value is a YYYY-MM-DD string. There is a valueAsDate property which is more useful, but Svelte doesn't currently use that.

Describe the solution you'd like

bind:valueAsDate or bind:value, but coercing the value to a date (or rather, using valueAsDate being the scenes for bind:value on date inputs).

Using bind:value is arguably better — I'm not sure if there are many situations where the string is more useful. But it would be a breaking change.

On the other hand, number and range inputs already coerce values to numbers. So by using bind:valueAsDate but not differentiating between bind:value and bind:valueAsNumber on numeric inputs, we'd be introducing an inconsistency. Blah.

Not sure which is preferable.

How important is this feature to you?

It'd be a nice to have.

@cimm
Copy link

cimm commented Nov 2, 2019

I am a Svelte newbie and I didn't even realize the date field wasn't coerced into a date.

Reading the tutorial I automatically assumed it would coerce all HTML fields correctly. My application mostly worked but started behaving strangely later in the flow. It took me a bit of time to realize it was the date string.

Not sure how valuable my input as a newbie is here but I would prefer the principle of least surprise, meaning bind:value would coerce what it can.

@jimmywarting
Copy link
Contributor

jimmywarting commented Nov 11, 2019

newbie here too, i would prefer if bind:valueAsDate and bind:valueAsNumber where used instead

I have worked with frontent for 10+ years and seen lib/frameworks come and go. Many reinvents the wheel and try to do form fields and validation in there own way - it's nothing but annoying to have to learn how to do something yet again.

think of it as this: if you where to port your application in a few years to/from svelte. the only thing two frameworks could have in common is if they used as much native functionality as possible

Would almost prefer bind:value to always be treated as a string also. When svelte treat numeric inputs value as number then it feels too magical and and somewhat unexpected. i might want to get something as a string sometimes


I think you got checkbox right, you bind the checked property instead of using bind:value

numeric inputs should not be treated any differently IMO.

@Conduitry
Copy link
Member

Closing in favor of #3937.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants