15

I want to make date range selection using jquery-ui datepicker. First change at #dteStart succeed to set minDate at #dteEnd. But #dteEnd failed to refresh its options on next change, if i alert DateOptions.minDate its value changed according to dateMin.

Maybe i miss something here...

$(document).ready(function () 
{
    $("#dteStart").datepicker()
    .change(function () 
    {
        dateStart = $(this).datepicker('getDate');
        dateMin = new Date(dateStart.getTime());
        dateMin.setDate(dateMin.getDate() + 1);

        var DateOptions = {
            dateformat: "mm/dd/yyyy",
            minDate: dateMin
        }
        $("#dteEnd").datepicker(DateOptions);
    });
});

TIA,

REV

v14nt0
  • 245
  • 2
  • 3
  • 11

4 Answers4

32

put $("#dteEnd").datepicker("destroy"); before $("#dteEnd").datepicker(DateOptions); and it will work fine.

TheVillageIdiot
  • 40,053
  • 20
  • 133
  • 188
26

If you just want to change the already configured options, you can also do:

$("#dteEnd").datepicker("option", DateOptions);

or

$("#dteEnd").datepicker("option", { dateFormat: "mm/dd/yyyy" });
Torge
  • 2,174
  • 1
  • 23
  • 33
  • 3
    For example: $( ".publishdatepicker" ).datepicker("option",{ yearRange: "-90:+1"}); – Pons Jul 10 '14 at 13:05
  • Your second line, doesn't work with me, only when dateformat is dateFormat (with a capitalized F) jQueryUI 1.10.2 – Leroy Meijer Jan 05 '16 at 08:08
  • This second line was actually not from me, someone else put it in there. But I corrected it. Thx. – Torge Jan 06 '16 at 15:31
5

The following jQuery helper function may be useful in such cases to preserve the original options:

$.fn.customizeDatepicker = function(newOptions) {
    var prevOptions = $(this).datepicker('option', 'all');
    $(this).datepicker('destroy').datepicker($.extend(prevOptions, newOptions));
    return this;
};

It saves the previous options and extends them with the new options.

bencergazda
  • 620
  • 8
  • 18
0

$('#divbspDate').data("DateTimePicker").destroy();

You can try this, for Date time picker it is working.

Malik
  • 3
  • 3