Created
January 10, 2020 08:32
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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