We are useing the default datepicker for jQuery ( http://jqueryui.com/datepicker/ ) but im trying to make a changeable datepicker.
I have a radio button that can be switched between a Delivery and a Pickup. I want costumers to be able to select Satherday when its pickup but unable to select sunday and satherday with Delivery.
I made some code but it doesnt seem to work
JS
$('input[name=method]').change(function() {
if ($(this).val() == 'pickup') {
$('.datepicker').datepicker({
beforeShowDay: function(date) {
var day = date.getDay();
return [(day != 0), ''];
}
});
}
else {
$('.datepicker').datepicker({
beforeShowDay: $.datepicker.noWeekends
});
}
});
HTML
<h3>Overige informatie</h3>
<label>Afhalen/Bezorgen</label>
<br>
<div id="project_basket_orderinfoform-method">
<label><input type="radio" id="project_basket_orderinfoform-method-pickup" name="method" value="pickup" checked="checked" class=" radio"/>Afhalen</label>
<label><input type="radio" id="project_basket_orderinfoform-method-deliver" name="method" value="deliver" class=" radio"/>Bezorgen</label>
<span class="required-marker">*</span>
</div>
<label for="project_basket_orderinfoform-delivery_date">Aflever-/afhaaldatum</label>
<br>
<input id="project_basket_orderinfoform-delivery_date" type="text" placeholder="" name="delivery_date" value="24-12-2012" class="datepicker datetime"/>
So basicly when i switch from Pickup to Delivery and back the datepicker doesnt change its setting beforeShowDay. I cant figure out whats going wrong… Im not that quite experienced with datepicker so i wonder did anyone else made this before or can someone see what is wrong with the code?
Once you instantiate the datepicker, you cannot change its settings without using the “option” option or you can destroy the datepicker and recreate it.