Should we really use html5 input date?

I just read Mark Pilgrim post about html5 widgets here:

http://diveintohtml5.ep.io/forms.html

It implies that these elements must be accepted because they return to input = text. However, on (admittedly short-term) testing, it seems to me that the date input behavior, at least in safari, is actually inferior to direct text input confirmed on the server.

Any views on this?

+4
source share
2 answers

As stated in your article and comments, there is no reason not to use this type of input.

For browsers that do not support type="date" , the attribute will be ignored and the field will be displayed as type="text" , since this is the default value.

You want to check this date on the server side. Remember:. Anyone can post anything in their scripts.

You can still check the client part of the data. There are methods for detecting HTML5 form support here: http://nicolahibbert.com/html5-forms-support-detection-javascript/

+1
source

Here's the reason not to use type="date" (or at least to do it carefully): localized date formats.

If you use <input type="date"> and the browser supports the date type, you must specify the value attribute in the ISO-8601 date format (for example, yyyy-MM-dd). If the browser does not support the date type, you will need to specify the date in the local user date format (for example, MM / dd / yyyy in the USA).

On the server side, you can probably be sloppy and do something like this:

 try parse date as ISO-8601 catch (Format Error) try parse date as local format catch (Format Error) show user error message 

If you want to be as clear as possible, you will need to perform some client-side discovery functions, then enable type="date" , and then change the date format of the value attribute, and possibly even produce a hidden form element that notifies the server that that the date format coming from the form should be ISO-8601.

+1
source

All Articles