Skip to content

Commit

Permalink
Merge pull request #209 from snake-345/master
Browse files Browse the repository at this point in the history
added check date in checkAndSetDefaultValue
  • Loading branch information
longbill committed Feb 3, 2016
2 parents 676998d + b1ca6c2 commit b3fd502
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions jquery.daterangepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -1082,13 +1082,21 @@
// set initiated to avoid triggerring datepicker-change event
initiated = false;
if(defaults.length >= 2){
setDateRange(moment(defaults[0], ___format, moment.locale(opt.language)).toDate(),moment(defaults[1], ___format, moment.locale(opt.language)).toDate());
setDateRange(getValidValue(defaults[0], ___format, moment.locale(opt.language)),getValidValue(defaults[1], ___format, moment.locale(opt.language)));
}
else if(defaults.length==1 && opt.singleDate){
setSingleDate(moment(defaults[0], ___format, moment.locale(opt.language)).toDate());
setSingleDate(getValidValue(defaults[0], ___format, moment.locale(opt.language)));
}

initiated = true;

function getValidValue(date, format, locale) {
if (moment(date, format, locale).isValid()) {
return moment(date, format, locale).toDate();
} else {
return moment().toDate()
}
}
}
}

Expand Down

0 comments on commit b3fd502

Please sign in to comment.