Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Datepicker: Adding dateFormat is giving an error

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?

like image 823
EricC Avatar asked Jun 07 '13 00:06

EricC


1 Answers

Use set Defaults for your format.

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

Now your dates shows the right format (i.e. 2013-06-12)

Right format

Updated JSFiddle here: http://jsfiddle.net/jaaqs/3/

like image 63
Bryan Hong Avatar answered Nov 11 '22 18:11

Bryan Hong