4

On site I have default datepicker initializated globally for all inputs with class input-date.

$('body').on('focus', '.input-date', function () {
  $(this).datepicker({
    changeMonth: true,
    changeYear: true,
    dateFormat: 'd.m.yy'
  });
});

But sometimes I need add some other options e.g. minDate for specific element. I already tried set this option and refresh it, but without success.

var dateField = $('#date');
dateField.datepicker('option', 'minDate', new Date());
dateField.datepicker('refresh');

So for now, only way how I managed to changed it it destroy it and create new one.

var dateField = $('#date');
dateField.datepicker('destroy');
dateField.datepicker(customOptions);

Is there any better way to do it?

7
  • are you sure you are referring the same element? because I see first you initialize '.input-date' and then '#date'
    – Praveen
    Commented Sep 3, 2013 at 15:58
  • 1
    seems fine here jsfiddle.net/arunpjohny/28NWZ/1 Commented Sep 3, 2013 at 15:59
  • Yes, I'm sure it's same element. I just address it with id so other datepicker are not changed.
    – s7anley
    Commented Sep 3, 2013 at 16:00
  • @s7anley is this similar to fiddle that Arun has created? Seems to be working.
    – Praveen
    Commented Sep 3, 2013 at 16:02
  • That is correct, but in my case I dont want to hook on some click event. Just want to change datepicker option.
    – s7anley
    Commented Sep 3, 2013 at 16:13

0

Browse other questions tagged or ask your own question.