Skip to content

Instantly share code, notes, and snippets.

@kutoi94
Created January 10, 2020 08:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kutoi94/5bdf5c78a2e45bf8529548bc546d3abe to your computer and use it in GitHub Desktop.
Save kutoi94/5bdf5c78a2e45bf8529548bc546d3abe to your computer and use it in GitHub Desktop.
Part 3 Series: Tạo và quản lý đặt phòng khách sạn với Meta Box
jQuery( function($) {
setTimeout(function(){
datepicker_reinstall();
console.log(disable_dates);
}, 1000);
function datepicker_reinstall(){
var dateFormat = "yy-mm-dd",
from = $( "#group_booking_check_in" ),
to = $( "#group_booking_check_out" );
from.add(to).datepicker('destroy');
from.datepicker({
minDate: 0,
defaultDate: "+1w",
beforeShowDay: function(date){
var string = jQuery.datepicker.formatDate('yy-mm-dd', date);
return [ disable_dates.indexOf(string) == -1 ]
}
})
.on( "change", function() {
to.datepicker( "option", "minDate", getDate( this ) );
});
to.datepicker({
defaultDate: "+1w",
beforeShowDay: function(date){
var string = jQuery.datepicker.formatDate('yy-mm-dd', date);
return [ disable_dates.indexOf(string) == -1 ]
}
})
.on( "change", function() {
from.datepicker( "option", "maxDate", getDate( this ) );
});
function getDate( element ) {
var date;
try {
date = $.datepicker.parseDate( dateFormat, element.value );
} catch( error ) {
date = null;
}
return date;
}
}
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment