date-picker icon indicating copy to clipboard operation
date-picker copied to clipboard

input control's value never gets updated unless 10 or 0 characters long

Open johnantoni opened this issue 4 years ago • 7 comments

Describe the bug Hi, I'm noticing that the input control never registers the value has been changed unless the input value is 0 or 10 characters (e.g. a date 2002-02-02) in length.

If it's 2002-02-0 it will not update the value.

But if you change 2002-02-0 to 2002-02-02 it will update the value, or if you change "2" to "".

To Reproduce Steps to reproduce the behavior:

  1. Go to date control

  2. input 2002-02-02

  3. change it to 2002-02-0

  4. look for the form value to change, doesn't change

  5. Go to date control

  6. input 2002-00

  7. change it to 2002-02-02

  8. look for the form value to change, it will only change when you enter 2002-02-02

Expected behavior Every time you change the value the input control's value should change.

Screenshots Screen Shot 2020-12-03 at 3 07 04 PM Screen Shot 2020-12-03 at 3 14 13 PM

johnantoni avatar Dec 03 '20 20:12 johnantoni

This was an intentional decision to ensure that the value is always a valid date (or empty string when input is cleared).

Perhaps we can be a bit more aggressive in setting to empty value - any invalid date should clear the value?

WickyNilliams avatar Dec 08 '20 15:12 WickyNilliams

Possible duplicate of https://github.com/duetds/date-picker/issues/47?

WickyNilliams avatar Dec 08 '20 15:12 WickyNilliams

Ok, thanks @WickyNilliams. It just seems strange that if you're editing the value via keyboard then the value you have on-screen is different from the one in the store until the value is a valid date or blank

johnantoni avatar Dec 08 '20 18:12 johnantoni

I have just checked the behaviour of the native <input type="date">...

On invalid date, its value property is set to an empty string (in chrome and FF). So that happily aligns with my proposal above. So I will go with that.

WickyNilliams avatar Dec 10 '20 13:12 WickyNilliams

If you want values as they are typed you could listen to an "input" event. But be aware you need a condition in your listener to filter out events from the year/month dropdowns. I may add a custom event for this purpose in future.

Edit: i just tested further and native date input does not raise input events for invalid dates. So you have no access to values as they are typed, unless you listen for keydown. I will endeavour to match native behaviour as much as possible.

WickyNilliams avatar Dec 10 '20 13:12 WickyNilliams

what if we format the dates manually if the user forgets to add preceding 0s. ie. use duetBlur to change 2020-1-1 to 2020-01-01 in the input. How can we update the date-picker in that scenario?

Wahaj10 avatar Apr 28 '21 19:04 Wahaj10

Looks like I found a way, I can manually set the value of the date-picker as well 👍

Wahaj10 avatar Apr 28 '21 19:04 Wahaj10