twill icon indicating copy to clipboard operation
twill copied to clipboard

Editing a date within the input manually doesn't update when saving

Open Tofandel opened this issue 1 year ago • 3 comments

Steps to reproduce

Add a datepicker field

 DatePicker::make()
  ->name('start_date')->label('Start date')
  ->time24h()
  ->allowInput()
  ->required(),

Edit the input field manually image Notice how the date picker picked up the edit image

Click save Reload the page The field is back to it's original value image

It works properly when editing via the Date picker and not the input

Tofandel avatar Dec 03 '24 12:12 Tofandel

I guess this is the same issue as #2667 with fix #2668

Tofandel avatar Dec 03 '24 13:12 Tofandel

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)

Tofandel avatar Dec 10 '24 11:12 Tofandel

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

Tofandel avatar Dec 10 '24 11:12 Tofandel