How to handle HTML5 type input date with localization?

I have some kind of date field in my application (supported by rails) and my locale is pt-BR (dd / mm / yyyy).

I know some browsers (like Chrome) support input type = date and in these browsers I would like to use the native datepicker and the date format (presentation format) is shown accordingly with the browser locale setting, although the field value (wire format) is still in ISO yyyy-mm-dd format.

In other browsers that don't support it (Firefox for example), I use the datepicker provided by javascript where the user focuses the field and the date is displayed with my standard pt-BR format (presentation format is wire format, localized).

I am switching between these two types via Modernizr.

However, the value (wired format) passed to the server is different depending on the approach, and I need to get the value on my server to be equal regardless of the user's browser.

How do I handle this situation? Should I ignore the type input date and only use one approach (change the type to text)?
Or do I need to format the value before sending it via javascript to "delocalize" the value?

Thanks in advance.

+3


source to share





All Articles