Skip to content

Instantly share code, notes, and snippets.

@alex-authlab
Created August 17, 2021 18:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alex-authlab/09577c5c061fc637b475284af0349883 to your computer and use it in GitHub Desktop.
Save alex-authlab/09577c5c061fc637b475284af0349883 to your computer and use it in GitHub Desktop.
// booking date check in > check out
// add the two class 'in-date' & 'out-date'
$( document ).ready(function() {
var check_in = flatpickr(".in-date",{dateFormat: "d/m/Y",});
var check_out = flatpickr(".out-date",{dateFormat: "d/m/Y",});
check_in.element.addEventListener("change", function(){
check_out.set( "minDate" , check_in.element.value );
});
check_out.element.addEventListener("change", function(){
check_in.set( "maxDate" , check_out.element.value );
});
});
@BenJamesAndo
Copy link

This is excellent. Thank you.
I wonder if it'd be possible to show an error message if the user tries to select an out date that is before the in date? On desktop it greys it out, which is great. But on Android and iPhone the mobile apps use their own calendar picker and so it doesn't show greyed out dates. If you select an out date that is before an in date on mobile it just clears your selection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment