I've searched here in SO and all around but no properly solutions founded for this issue. With jQueryUI DatePicker I need to select a recursive date for all years, so I don't wanna show year selection, 'cause it doesn't make sense.
How can I obtain this inside the call like the following?
$('#myInput').datepicker({ dateFormat: "dd/mm" });
Note: I can't use css solution as suggested here .ui-datepicker-year{
display:none;
}
because there are other datepickers in the same page.
Any help will be appreciated.
Thanks in advance.
I know it's a pretty old quesion, but maybe it will be helpful for someone. If you set the option changeYear: false
you can see a <span>
with an year value, but if you set changeYear: true
you can see a <select>
. We can use this difference like this:
$(function() {
$("#year-datepicker").datepicker({
changeMonth: true,
changeYear: true
});
$("#no-year-datepicker").datepicker({
dateFormat: "MM d",
changeMonth: true,
changeYear: false
});
});
span.ui-datepicker-year {
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" />
<p>With year: <input type="text" id="year-datepicker"></p>
<p>Without year: <input type="text" id="no-year-datepicker"></p>
Try this:
$("#myInput").datepicker();
$("#myInput").datepicker("option", "dateFormat", "dd/mm");
As jQuery UI DatePicker Documentaion,
http://docs.jquery.com/UI/Datepicker#option-dateFormat
You have to call below function in Initialization.
$("#myInput").datepicker({ dateFormat: "dd/mm" });
It will not work if you call it after init method.
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