We help IT Professionals succeed at work.

Date input localization problem

In our web based software there is a date input which works well in Chrome, Edge and Opera according to localization, but it doesn't work in Firefox and Safari.

As a workaround we built the Modernizr extension like this:
<script>
    $(function(){          
        if (!Modernizr.inputtypes.date) {
            $('input[type=date]').datepicker({
                  dateFormat : 'yy-mm-dd'
                }
             );
        }
    });
</script>

The date shows well with the default value e.g. 2017-11-02 but when the user clicks in it the format changes and it sets a new date (1902 jan. 2).

I attached the pictures

default_value.jpg = Default value
on_focus.jpg = Clicked
after_focus_click.jpg = when it loses focus, without changing the value
on_focus.jpg
after_focus_click.jpg
default_value.jpg
Comment
Watch Question

Most Valuable Expert 2017
Distinguished Expert 2019

Commented:
datePicker - is that from jQueryUI or another library?

Author

Commented:
It is from jQueryUI. Thank you.
Most Valuable Expert 2017
Distinguished Expert 2019
Commented:
I put this sample together using your code - seems to work fine (bar the datepicker background not showing which I will fix later)

http://www.marcorpsa.com/ee/t2774.html