Skip to content

Instantly share code, notes, and snippets.

@akira1908jp
Created June 26, 2013 09:09
Show Gist options
  • Save akira1908jp/5865932 to your computer and use it in GitHub Desktop.
Save akira1908jp/5865932 to your computer and use it in GitHub Desktop.
min_year, min_month, min_day,max_year, max_month, max_dayは与える引数
var pickerOption = (function(){
var _format = 'yy-mm-dd'
,_min = (function () {
return getDate(min_year, min_month, min_day);
})(),
_max = (function () {
return getDate(max_year, max_month, max_day);
})();
function getDate(year, month, day) {
var date = new Date(year, month - 1, day);
return !/Invalid|NaN/.test(date.toString()) ? date : null;
}
return {
dateFormat : _format,
minDate : _min,
maxDate : _max,
onClose : function(dateText,inst) {
var inputDate = new Date(dateText);
if ("id" in inst && /To|From/.test(inst.id) && !/Invalid|NaN/.test(inputDate.toString())) {
if (inputDate >_max) {
$(this).val(convertDateToString(_max, '-', 0));
}
if (inputDate < _min) {
$(this).val(convertDateToString(_min, '-', 0));
}
}
}
};
})();
$("#hogeFrom").datepicker(pickerOption);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment