Skip to content
This repository has been archived by the owner on Jul 16, 2022. It is now read-only.

Commit

Permalink
Fix for #97 and generally for setting date outside of limits
Browse files Browse the repository at this point in the history
  • Loading branch information
nazar-pc committed Aug 24, 2016
1 parent 9256399 commit 9d92420
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions js/jquery.pickmeup.js
Original file line number Diff line number Diff line change
Expand Up @@ -921,10 +921,14 @@
options.date.push(parseDate(options.date[0]));
}
}
for (i = 0; i < options.date.length; ++i) {
options.date[i] = correct_date_outside_of_limit(options.date[i], options.min, options.max);
}
} else {
if(options.date instanceof Array) {
options.date = options.date[0];
}
options.date = correct_date_outside_of_limit(options.date, options.min, options.max);
}
if (!options.select_day) {
if (options.date instanceof Array) {
Expand Down Expand Up @@ -967,6 +971,14 @@
$(document).off(options.events_namespace);
$(this.pickmeup).remove();
}
function correct_date_outside_of_limit (date, min, max) {
if (min && min > date) {
return new Date(min);
} else if (max && max < date) {
return new Date(max);
}
return date;
}
$.fn.pickmeup = function (initial_options) {
if (typeof initial_options === 'string') {
var data,
Expand Down Expand Up @@ -1035,20 +1047,14 @@
options.mode = /single|multiple|range/.test(options.mode) ? options.mode : 'single';
if (options.min) {
options.min = parseDate(options.min, options.format, options.separator, options.locale);
if (!options.select_day) {
options.min.setDate(1);
}
}
if (options.max) {
options.max = parseDate(options.max, options.format, options.separator, options.locale);
}
if (!options.select_day) {
if (options.min) {
options.min = new Date(options.min);
options.min.setDate(1);
options.min = options.min.valueOf();
}
if (options.max) {
options.max = new Date(options.max);
if (!options.select_day) {
options.max.setDate(1);
options.max = options.max.valueOf();
}
}
var cnt,
Expand Down

0 comments on commit 9d92420

Please sign in to comment.