I have multiple datepickers on a page... all seems to be working fine except I the altfield part...
Is something like this possible??
$(document).ready(function(){
$( ".datepicker" ).datepicker({
beforeShowDay: function(date){ return [(date.getDay() == 1 || date.getDay() == 4), ""] },
showOn: "button",
buttonText: "Book now...",
showWeek: true,
firstDay: 1,
onSelect: function(date) {
$(this).parent().find('.selecteddate').prepend("Date: " + $(this).parent().find('.datepicker').val() + " - <a href='javascript:;' class='cleardate'>clear date</a>");
$(this).parent().find('button').hide();
},
dateFormat: "DD, d MM, yy",
altField: $(this).closest('div').find('.datepickeralt'),
altFormat: "dd/mm/yy",
navigationAsDateFormat: true,
minDate: 0,
});
$(".cleardate").live('click',function(){
$(this).closest('div').find('.datepicker').datepicker("setDate", null);
$(this).closest('div').find('.datepickeralt').val("");
$(this).closest('div').find('button').show();
$(this).parent().html("");
});
});
Yes you can do exactly that, you just need to instantiate the date pickers with a .each()
loop, like this:
$('.datepicker').each(function() {
$(this).datepicker({
altField: $(this).closest('div').find('.datepickeralt')
});
});
This way inside the .each()
this
refers to what you want, each individual date picker, then finding its alt field. You can give it a try here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With