The datepicker functionality has an issue when a user changes the text
value of the input after a date has been selected. Example of this:
Input value is set to:
08-22-2019
User decides they want change the date to:
08-23-2019
So, they put the cursor after the 22 and change the last 2 to a 3.
During this editing, if we update the value that the datepicker looks
at, it gets confused and the value ends up looking like:
8-232-019
This value cannot be parsed by the datepicker and we end up with a null
Date() value. However, the value inside the input looks correct. The
emitted value from the input, however, ends up being null.
We tried a few workarounds here.
Tried setting this.value = new Date(textualValue)
This was a problem because the moment you removed the 2 in the
example above, the value ended up looking like: 08-22-019. The
2 from 2019 moved into the day section of the mask and that value
is actually a valid date! The date turns out to parse into
08-22-2019, which is what we already had. This, in turn, would
fire off an event on the datepicker which would re-update its
internal stuff and kick the cursor to the end of the line.
Making it literally impossible to change the date manually
unless you deleted every character and reentered the whole
date by hand.
Tried creating a hidden input element that the datepicker was tied to
and then manually update the shown input based on changes. This
caused a lot of issues where we had to manually update the mask on
every event and make sure we updated both values on the hidden and
shown input. This became messy quickly.
The solution that's being committed here. We don't fire off a
selected event on input changes. We instead just update the masked
value and store the masked value in a separate store. Then, on blur
events, the change event will look to see if the date is null (due to
the description of the original issue above) and if the textual value
is not null. If so, the textual value wins and we create a new date
object based on that info. Otherwise, the datepicker value wins.
This prevents the input text changing while the user is typing and
throws out an event on blur with the updated value.