I currently have a field in my form.
Everything working perfectly …
The only issue is …
It is entering this format yyyy-mm-dd
I needed to handle this for the dd/mm/yyyy format
What would be the way to do this?
Calendar and everything else …
<%= text_input f, :expira, class: "form-control span2 col-md-9", type: "date" %>
<%= error_tag f, :expira %>
The thing is, when you use an input HTML field with the attribute
type=date, browsers will configure this field differently based on:
- what browser it is (FireFox shows it differently from Chrome which shows it differently from Internet Explorer). Mobile browsers also do their own thing.
- What locale the user is in: In locales where the
dd-mm-yyyy format is used, that one might be shown. In locales where
mm-dd-yyyy is used, that one might be shown.
- Some browsers still do not support it, and then it will degrade to a normal text field.
Information on the Mozilla Developers Network. Note that the value that is used behind the schenes (for both setting and retrieving its value) will always be in the ISO 8601 format (that is the
Oh, and if it is at all possible to educate the users of your application to use the
yyyy-mm-dd format, please do; that would be the absolute best, future-proof, solution .
Considering that is the ISO8601 DateTime standard, anyone that is not using it will break somehow and somewhere (the heck is mm-dd-yyyy, that is weirdly mixed… o.O).
That is what they use in the United States, Micronesia and some other countries.
I have been using long time ago jqueryui datepicker.
I would not recommand jquery now, but it is possible to define date format on the ui side, then it would be converted to ISO8601.
In my country, it’s dd/mm/yyyy
Not here, and I work in the central USA. ^.^
ISO8601 all the way!