Reputation: 4559
I have a datepicker that I create with the following code.
$('.myClass').find('input').datepicker({showOn: 'button',
buttonText: 'Date'});
if the user checks a checkbox I want to change the options of that datepicker. I tried to do the following but I am not having any luck.
$('.myClass').datepicker('destroy');
//I didnt have this line intially but was reading it may be necessary
$('.myClass').removeClass('hasDatepicker').removeAttr('id');;
$('.myClass').find('input').datepicker({showOn: 'button',
buttonText: 'Date', firstDay: 1, showWeek: true});
Upvotes: 0
Views: 72
Reputation: 4992
Is there some reason you can't pass in the modifications to your datepicker options object on change based on whether the box is checked? Normally I wouldn't suggest destroying and recreating the datepicker unless you really needed to. The datepicker widget allows you to change options dynamically, like so:
$("#theCheckbox").change(function() {
$(".myClass").datepicker("option", this.checked ?
{
firstDay: 1,
showWeek: true
} :
{
firstDay: 0,
showWeek: false
});
});
Upvotes: 1