I have a page where I keep track of various dates. So I end up using datepicker through jquery anywhere from 10-200 times. I want to set the default for all cases of datepicker to the 'yy-mm-dd' - but I can't seem to figure out how to set that?
Initialize the datepicker and specify the date format in "yyyy-mm-dd". JavaScript Code : $( "#datepicker" ). datepicker(); $( "#datepicker" ).
To set and get the input type date in dd-mm-yyyy format we will use <input> type attribute. The <input> type attribute is used to define a date picker or control field. In this attribute, you can set the range from which day-month-year to which day-month-year date can be selected from.
I end up using datepicker through jquery anywhere from 10-200 times.
I'm assuming you're calling datepicker()
separately for each input, probably by id
. There's no need for that.
Use a class
as a hook on your input:
<input class="my-datepicker">
Then call datepicker
on elements with that class with your default configuration:
$('.my-datepicker').datepicker({
dateFormat: 'yy-mm-dd'
});
When you need a different configuration, use/assign a different class name.
You can also use setDefaults
(probably what you're looking for):
$.datepicker.setDefaults({
dateFormat: 'yy-mm-dd'
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With