Created
March 16, 2013 20:16
-
-
Save simonpioli/5178132 to your computer and use it in GitHub Desktop.
Date-pickers to show between 2 dates using jQuery UI Datepicker
This file contains 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
$(function() { | |
var dates = $( "#from, #to" ).datepicker({ | |
defaultDate: "+1w", | |
numberOfMonths: 1, | |
beforeShow: function( ) { | |
var other = this.id == "from" ? "#to" : "#from"; | |
var option = this.id == "from" ? "maxDate" : "minDate"; | |
var selectedDate = $(other).datepicker('getDate'); | |
$(this).datepicker( "option", option, selectedDate ); | |
} | |
}).change(function(){ | |
var other = this.id == "from" ? "#to" : "#from"; | |
if ( $('#from').datepicker('getDate') > $('#to').datepicker('getDate') ) | |
$(other).datepicker('setDate', $(this).datepicker('getDate') ); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment