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

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

Open
Tofandel opened this issue Dec 3, 2024 · 3 comments
Open

Comments

@Tofandel
Copy link
Contributor

Tofandel commented Dec 3, 2024

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
Copy link
Contributor Author

Tofandel commented Dec 3, 2024

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

@Tofandel
Copy link
Contributor Author

Tofandel commented Dec 10, 2024

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
Copy link
Contributor Author

Tofandel commented Dec 10, 2024

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

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

1 participant