$(function(){
initDatePicker();
})
function initDatePicker(){
// do a loop for custom property on each element
$('.datepicker').each(function(){
// you can find available formats here : http://api.jqueryui.com/datepicker/#utility-formatDate
$(this).datepicker({
dateFormat:'mm/dd/yy'
});
// set minimum date from data attribute.
if (typeof $(this).data('mindate') != 'undefined') {
$(this).datepicker('option','minDate',$(this).data('mindate'));
}
// set maximum date from data attribute.
if (typeof $(this).data('maxdate') != 'undefined') {
$(this).datepicker('option','maxDate',$(this).data('maxdate'));
}
$(this).on('change',function(){
parseInputDate(this);
// now, set date relations :)
if (typeof $(this).data('nextelem') != 'undefined') {
$($(this).data('nextelem')).datepicker( "option", "minDate", getDate( this ) );
}
if (typeof $(this).data('prevelem') != 'undefined') {
$($(this).data('prevelem')).datepicker( "option", "maxDate", getDate( this ) );
}
});
});
}
// get date function taken from : http://jqueryui.com/datepicker/#date-range
function getDate( element ) {
var date;
try {
date = $.datepicker.parseDate( $(element).datepicker('option','dateFormat'), element.value );
} catch( error ) {
date = null;
}
return date;
}
function parseInputDate(elm) {
var currDate = new Date(),
monDt = (('0'+(currDate.getMonth()+1)).slice(-2)+('0'+currDate.getDate()).slice(-2)), // get current month+date to compare
inputVal = $(elm).val().match(/\d{2}/gi), // split date components into array of [dd,mm,yy,yy]
format = $(elm).datepicker("option", "dateFormat"); // get current element's datepicker format
// check if it's already a valid entry, then do nothing
if ($(elm).val() == $.datepicker.formatDate(format,$(elm).datepicker('getDate'))) return;
var isValidDate = function(yyyy,mm,dd) {
var dt = new...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.