guillaumepotier / Parsley.js

Validate your forms, frontend, without writing a single line of javascript
http://parsleyjs.org
MIT License
9.05k stars 1.32k forks source link

Problem validating inputs min/max of type "datetime-local" #1372

Open victornoleto opened 9 months ago

victornoleto commented 9 months ago

What kind of issue is this? (put 'x' between the square brackets)

I'm developing a linked dates component and for that I would like to use the native date and time selection inputs, datetime-local.

The objective is that in the change event of the "start input", this value is set in the "min" attribute of the "end input". And likewise, in the change event the "end input", the value is set in the "max" attribute of the "start input".

I do this to take advantage of the component's native behavior that blocks the selection of some dates according to the min/max fields. This is working wonderfully.

The problem comes from how parsley uses the min and max attributes. Because (and I can't figure out why) it can't correctly validate if one date is less/greater than another in the format this native input uses, "YYYY-MM-DDTHH:mm".

In the images below I exemplify what happened.

The code: 2023-07-28_13-50

The generated output: 2023-07-28_13-50_1

Start input limited to dates below than "2023-07-20T10:00" 2023-07-28_13-50_2

End input limited to dates higher than "2023-07-10T10:00" 2023-07-28_13-50_3

The error: 2023-07-28_13-50_4]

marcandre commented 9 months ago

Thanks for the detailed report. I agree this looks like a bug. Do you have a codepen or similar I could look at?

victornoleto commented 9 months ago

Thanks for the detailed report. I agree this looks like a bug. Do you have a codepen or similar I could look at?

Sure! Here is it: https://jsfiddle.net/victorsysout/93sfoLmh/25/