Editing a date within the input manually doesn't update when saving
Steps to reproduce
Add a datepicker field
DatePicker::make()
->name('start_date')->label('Start date')
->time24h()
->allowInput()
->required(),
Edit the input field manually
Notice how the date picker picked up the edit
Click save
Reload the page
The field is back to it's original value
It works properly when editing via the Date picker and not the input
I guess this is the same issue as #2667 with fix #2668
A follow up issue
With the fix, the display format is not properly parsable by Date in some locales, while it's a good human readable format the month names are localized and then do not parse properly eg in fr
new Date('décembre 11, 2024 12:00') // Invalid date
I guess we would need to replace the month names in the current locale into the en locale before parsing it or remove the accents
new Date('décembre 11, 2024 12:00'.normalize("NFD").replace(/[\u0300-\u036f]/g, "")) // Wed Dec 11 2024 12:00:00 GMT+0100 (heure normale d’Europe centrale)
Seems the rest of the logic is also quite flawed
const fullFormat = 'yyyy-MM-dd HH:mm:ss';
if (date.length === fullFormat.length) {
return parse(date + 'Z', fullFormat + 'X', Date.UTC());
}
Format check on format length instead of a regex
This means the following date mars 11, 2024 12:00 which has the same length as the format will pass into that condition and parse to an invalid date