Closed andapopovici closed 5 years ago
Hi @andapopovici, sorry I didn't see this come through over the holidays. I will review it tomorrow. Thanks for your contribution!
@andapopovici thanks for this. I'm not going to pull it because a) I don't want to start adding event handlers in HTML attributes, and b) I'd like to create a more general validation which also handles days of the month, months of the year, etc. There are some good ideas here (I had forgotten the distinction between setting the year using the Date
constructor versus using setFullYear()
) that I hope to incorporate.
If you're interested in continuing to work on this, I'd be happy to help you get it into shape to be included.
There's no reason to restrict years to four digits. Admittedly it'll be a long, long time before five-digit years are required, but they're still valid years, so why forbid them? Short of actual technical restrictions, at least. I tested just now and found that the JS Date constructor can understand years of six digits.
Added an 'oninput' callback on the Date block year input which points to the 'validateYear' function on the runtime.
Restriction to 4 characters is done by checking the year length and setting the value to the sliced 4 digit value if the limit is reached.
Removed the 'min=0' attribute and added a manual check because when editing a field and reaching the maximum value, a leading 0 that cannot be deleted is left on the field. e.g. if trying to input 99999 the field becomes 0 and so only 3 other characters can be set.
Tested on Chrome 47.0.2526.106 m, Firefox 43.0.2
P.S. Apologies for breaking the build the first time, I hadn't run the tests locally...