Created
August 1, 2013 06:14
-
-
Save Gerhard-Kanzler/6128819 to your computer and use it in GitHub Desktop.
jQuery UI Datepicker with dependencies on dates.
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
// Inputs must be in the same <form> | |
// This is not Tested, if there are error comment please | |
var selectorFromInput = '.arrival'; | |
var selectorToInput = '.departure'; | |
var addDays = 7; | |
$( selectorFromInput + ", " + selectorToInput).datepicker({ | |
minDate:0, | |
firstDay:1, | |
onSelect:function (dateText, inst) { | |
if($(this).hasClass(selectorFromInput.replace('.', ''))) { | |
var quickfinderform = $(this).parents('form:first'); | |
if(quickfinderform) { | |
if ($(this).hasClass(selectorFromInput.replace('.', ''))) { | |
var nextdate = $("input"+selectorToInput, quickfinderform); | |
var currdate = $(this).datepicker("getDate"); | |
var dateTime = $(this).datepicker("getDate"); | |
var departureDate = quickfinderform.find('input'+selectorToInput).datepicker('getDate'); | |
nextdate.datepicker("option", "minDate", dateTime ); | |
if( currdate >= departureDate ){ | |
currdate.setDate(currdate.getDate() + addDays); | |
nextdate.datepicker("setDate", currdate); | |
} | |
} | |
} | |
} | |
$(this).trigger('change'); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment