I am testing picking a daterange using this example: http://salman-w.blogspot.no/2013/01/jquery-ui-datepicker-examples.html#example-7
I want to change the dateFormat, but adding that gives the following error in the console: "Uncaught Unexpected literal at position 2"
I add one line (3rd line) for dateFormat like this:
$(function() {
$("#datepicker").datepicker({
dateFormat: "yy-mm-dd",
beforeShowDay: function(date) {
var date1 = $.datepicker.parseDate($.datepicker._defaults.dateFormat, $("#input1").val());
var date2 = $.datepicker.parseDate($.datepicker._defaults.dateFormat, $("#input2").val());
return [true, date1 && ((date.getTime() == date1.getTime()) || (date2 && date >= date1 && date <= date2)) ? "dp-highlight" : ""];
},
onSelect: function(dateText, inst) {
var date1 = $.datepicker.parseDate($.datepicker._defaults.dateFormat, $("#input1").val());
var date2 = $.datepicker.parseDate($.datepicker._defaults.dateFormat, $("#input2").val());
if (!date1 || date2) {
$("#input1").val(dateText);
$("#input2").val("");
$(this).datepicker("option", "minDate", dateText);
} else {
$("#input2").val(dateText);
$(this).datepicker("option", "minDate", null);
}
}
});
});
Or see jsfiddle for a example of the error: http://jsfiddle.net/jaaqs/
So, how can I change the dateFormat for this datepicker-range-example?
Use set Defaults for your format.
$.datepicker.setDefaults({
dateFormat: 'yy-mm-dd'
});
Now your dates shows the right format (i.e. 2013-06-12)
Updated JSFiddle here: http://jsfiddle.net/jaaqs/3/
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