I'm using an input mask to enforce the MM/DD/YYYY
format on <input type="text">
.
I want to use autocomplete="bday"
, but I don't want to use the hyphen format specified by WHATWG.
What can I do about this? Can I expect mobile browsers (mainly iOS/Android) to enter the fields into this box correctly.
P粉0051346852024-03-22 12:01:29
In an ideal world, your input should be of date type rather than text type. In theory, it has the following advantages:
But in practice,
Using the most professionally appropriate input type for a given field if one exists (here, date) is usually the best thing you can do, and will definitely be better in the long run from both a user and development perspective is the best thing you can do/maintain the perspective. It's guaranteed by standards, which means you can expect better support over time without having to do anything on your part, and the feature won't suddenly disappear.
However, the loss of control over precise appearance in particular, and the current lack of support, especially on probably most importantly mobile phones, unfortunately leads to the selection of text type input, a series of more or less accessible Combo boxes and/or calendars which are not very accessible most of the time, rather than just standard input dates.
Autocomplete content always populates fields in the yyyy-mm-dd format, which conflicts with your preferred format, and you cannot change it. So you don't have many solutions:
Both will make your input field less stable, less reliable, and less understandable to users. I guess it's not easy, maybe even impossible, to reliably detect browser autocomplete on all browsers, and when the interface says "write date in mm/dd/yyyy format" and the field contains yyyy-mm, Users may get confused - dd (Which format should I use? Which format is correct? What to write in the field now or what to give as instructions?)
Date type input will take away all the hassle, whether you want it or not, this is my final suggestion. We can expect that accessibility and support will improve over time without any action on your part. Entering dates has improved a lot since it was introduced a few years ago. Forget about pixel-perfect designs. Use standards wherever possible.