Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save onionstand/b006d424c220c412c7c6fae809d2f67a to your computer and use it in GitHub Desktop.
Save onionstand/b006d424c220c412c7c6fae809d2f67a to your computer and use it in GitHub Desktop.
Implementation of disabled elements for foundation datepicker project https://github.com/najlepsiwebdesigner/foundation-datepicker/
// implementation of disabled form fields
var nowTemp = new Date();
var now = new Date(nowTemp.getFullYear(), nowTemp.getMonth(), nowTemp.getDate(), 0, 0, 0, 0);
var checkin = $('#dpd1').fdatepicker({
onRender: function (date) {
return date.valueOf() < now.valueOf() ? 'disabled' : '';
}
}).on('changeDate', function (ev) {
if(ev.date){
if (ev.date.valueOf() > checkout.date.valueOf()) {
var newDate = new Date(ev.date)
newDate.setDate(newDate.getDate() + 1);
checkout.update(newDate);
checkin.hide();
}
}
$('#dpd2')[0].focus();
}).data('datepicker');
var checkout = $('#dpd2').fdatepicker({
onRender: function (date) {
return date.valueOf() <= checkin.date.valueOf() ? 'disabled' : '';
}
}).on('changeDate', function (ev) {
checkout.hide();
}).data('datepicker');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment