Setting default date format for datepicker?

I have a page where I track various dates. So I end up using datepicker through jquery anywhere from 10-200 times. I want to set the default value for all datepicker cases to "yy-mm-dd" - but I can't figure out how to set this?

+6
source share
2 answers

I end up using datepicker through jquery anywhere from 10-200 times.

I assume that you call datepicker() separately for each login, possibly with id . There is no need.

Use class as a hook on your input:

 <input class="my-datepicker"> 

Then call datepicker for elements with this class with your default configuration:

 $('.my-datepicker').datepicker({ dateFormat: 'yy-mm-dd' }); 

If you need a different configuration, use / assign a different class name.

You can also use setDefaults (maybe what you are looking for):

 $.datepicker.setDefaults({ dateFormat: 'yy-mm-dd' }); 
+21
source

Go to jquery.ui.datepicker.js file.

 function Datepicker() { dateFormat: 'mm/dd/yy' } 

Change it in the format you prefer. It will change the format for your entire site.

-5
source

Source: https://habr.com/ru/post/909120/


All Articles