I guys i'm using a datetimepicker by trentrichardson.com.
I have a form with two input fields : from and to and i want to be able to set dynamically a minDate to my "to" field equal to the value of my "from" field.
I know i should use a beforShow option but don't know how to implement the function.
$('.from,.to').datetimepicker({
beforeShow: customRange
});
EDITED/SOLUTION
function customRange(input) {
if (input.id == 'to') {
var x=$('#from').datepicker("getDate");
$( ".to" ).datepicker( "option", "minDate",x );
}
else if (input.id == 'from') {
var x=$('#to').datepicker("getDate");
$( ".from" ).datepicker( "option", "maxDate",x );
} }
you can set and get minDate dynamically with setter and getter:
//getter
var minDate = $( ".selector" ).datepicker( "option", "minDate" );
//setter
$( ".selector" ).datepicker( "option", "minDate", new Date(2007, 1 - 1, 1) );
If you have two textboxes with corresponding IDs from and to and you want the minDate of to to be the selected date of from then do the following:
$("#from").datepicker({
minDate: 0, // to disable past dates (skip if not needed)
onClose: function(selectedDate) {
// Set the minDate of 'to' as the selectedDate of 'from'
$("#to").datepicker("option", "minDate", selectedDate);
}
});
$("#to").datepicker();
You can restrict the datepicker range.
But you want to set this range on creation of the datepicker on the "from". I made you a demo which seems to work OK as far as I understand the question.