mirror of
https://github.com/frappe/air-datepicker.git
synced 2026-01-14 11:01:22 +08:00
add time validation, improve time change when range is true
This commit is contained in:
parent
dffa4429a7
commit
1ca88e6d0a
47
dist/js/datepicker.js
vendored
47
dist/js/datepicker.js
vendored
@ -381,6 +381,8 @@ var Datepicker;
|
|||||||
|
|
||||||
if (!(date instanceof Date)) return;
|
if (!(date instanceof Date)) return;
|
||||||
|
|
||||||
|
this.lastSelectedDate = date;
|
||||||
|
|
||||||
_this._trigger('selectDate', date);
|
_this._trigger('selectDate', date);
|
||||||
|
|
||||||
//TODO стоит убрать в timepicker.js
|
//TODO стоит убрать в timepicker.js
|
||||||
@ -465,6 +467,9 @@ var Datepicker;
|
|||||||
if (!_this.selectedDates.length) {
|
if (!_this.selectedDates.length) {
|
||||||
_this.minRange = '';
|
_this.minRange = '';
|
||||||
_this.maxRange = '';
|
_this.maxRange = '';
|
||||||
|
_this.lastSelectedDate = '';
|
||||||
|
} else {
|
||||||
|
_this.lastSelectedDate = _this.selectedDates[_this.selectedDates.length - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
_this.views[_this.currentView]._render();
|
_this.views[_this.currentView]._render();
|
||||||
@ -528,6 +533,12 @@ var Datepicker;
|
|||||||
this.$datepicker.addClass(this.opts.classes)
|
this.$datepicker.addClass(this.opts.classes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.opts.timepicker) {
|
||||||
|
this.timepicker._handleDate(this.lastSelectedDate);
|
||||||
|
this.timepicker._updateRanges();
|
||||||
|
this.timepicker._updateCurrentTime()
|
||||||
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -1082,7 +1093,7 @@ var Datepicker;
|
|||||||
|
|
||||||
if (selectedDates.length) {
|
if (selectedDates.length) {
|
||||||
selected = true;
|
selected = true;
|
||||||
date = this.selectedDates[this.selectedDates.length - 1]
|
date = this.lastSelectedDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
date.setHours(h);
|
date.setHours(h);
|
||||||
@ -1091,7 +1102,6 @@ var Datepicker;
|
|||||||
if (!selected) {
|
if (!selected) {
|
||||||
this.selectDate(date);
|
this.selectDate(date);
|
||||||
} else {
|
} else {
|
||||||
this.selectedDates[selectedDates.length - 1] = date;
|
|
||||||
this._setInputValue();
|
this._setInputValue();
|
||||||
this._triggerOnChange();
|
this._triggerOnChange();
|
||||||
}
|
}
|
||||||
@ -1812,12 +1822,13 @@ var Datepicker;
|
|||||||
},
|
},
|
||||||
|
|
||||||
_setDefaultMinMaxTime: function () {
|
_setDefaultMinMaxTime: function () {
|
||||||
var maxHours = 23;
|
var maxHours = 23,
|
||||||
|
opts = this.opts;
|
||||||
|
|
||||||
this.minHours = this.opts.minHours;
|
this.minHours = opts.minHours < 0 || opts.minHours > maxHours ? 0 : opts.minHours;
|
||||||
this.minMinutes = this.opts.minMinutes;
|
this.minMinutes = opts.minMinutes < 0 || opts.minMinutes > 59 ? 0 : opts.minMinutes;
|
||||||
this.maxHours = this.opts.maxHours > maxHours ? maxHours : this.opts.maxHours;
|
this.maxHours = opts.maxHours < 0 || opts.maxHours > maxHours ? maxHours : opts.maxHours;
|
||||||
this.maxMinutes = this.opts.maxMinutes > 59 ? 59 : this.opts.maxMinutes;
|
this.maxMinutes = opts.maxMinutes < 0 || opts.maxMinutes > 59 ? 59 : opts.maxMinutes;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1887,19 +1898,26 @@ var Datepicker;
|
|||||||
}).change();
|
}).change();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets minHours, minMinutes etc. from date. If date is not passed, than sets
|
||||||
|
* values from options
|
||||||
|
* @param [date] {object} - Date object, to get values from
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
_handleDate: function (date) {
|
_handleDate: function (date) {
|
||||||
if (datepicker.isSame(date, this.d.opts.minDate)) {
|
this._setDefaultMinMaxTime();
|
||||||
this._setMinTimeFromDate(this.d.opts.minDate);
|
|
||||||
} else if (datepicker.isSame(date, this.d.opts.maxDate)) {
|
if (date) {
|
||||||
this._setMaxTimeFromDate(this.d.opts.maxDate);
|
if (datepicker.isSame(date, this.d.opts.minDate)) {
|
||||||
} else {
|
this._setMinTimeFromDate(this.d.opts.minDate);
|
||||||
this._setDefaultMinMaxTime();
|
} else if (datepicker.isSame(date, this.d.opts.maxDate)) {
|
||||||
|
this._setMaxTimeFromDate(this.d.opts.maxDate);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this._validateHoursMinutes();
|
this._validateHoursMinutes();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
// Events
|
// Events
|
||||||
// -------------------------------------------------
|
// -------------------------------------------------
|
||||||
|
|
||||||
@ -1917,6 +1935,5 @@ var Datepicker;
|
|||||||
this._updateRanges();
|
this._updateRanges();
|
||||||
this._updateCurrentTime();
|
this._updateCurrentTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
})(window, jQuery, Datepicker);
|
})(window, jQuery, Datepicker);
|
||||||
|
|||||||
2
dist/js/datepicker.min.js
vendored
2
dist/js/datepicker.min.js
vendored
File diff suppressed because one or more lines are too long
@ -381,6 +381,8 @@ var Datepicker;
|
|||||||
|
|
||||||
if (!(date instanceof Date)) return;
|
if (!(date instanceof Date)) return;
|
||||||
|
|
||||||
|
this.lastSelectedDate = date;
|
||||||
|
|
||||||
_this._trigger('selectDate', date);
|
_this._trigger('selectDate', date);
|
||||||
|
|
||||||
//TODO стоит убрать в timepicker.js
|
//TODO стоит убрать в timepicker.js
|
||||||
@ -465,6 +467,9 @@ var Datepicker;
|
|||||||
if (!_this.selectedDates.length) {
|
if (!_this.selectedDates.length) {
|
||||||
_this.minRange = '';
|
_this.minRange = '';
|
||||||
_this.maxRange = '';
|
_this.maxRange = '';
|
||||||
|
_this.lastSelectedDate = '';
|
||||||
|
} else {
|
||||||
|
_this.lastSelectedDate = _this.selectedDates[_this.selectedDates.length - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
_this.views[_this.currentView]._render();
|
_this.views[_this.currentView]._render();
|
||||||
@ -528,6 +533,12 @@ var Datepicker;
|
|||||||
this.$datepicker.addClass(this.opts.classes)
|
this.$datepicker.addClass(this.opts.classes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.opts.timepicker) {
|
||||||
|
this.timepicker._handleDate(this.lastSelectedDate);
|
||||||
|
this.timepicker._updateRanges();
|
||||||
|
this.timepicker._updateCurrentTime()
|
||||||
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -1082,7 +1093,7 @@ var Datepicker;
|
|||||||
|
|
||||||
if (selectedDates.length) {
|
if (selectedDates.length) {
|
||||||
selected = true;
|
selected = true;
|
||||||
date = this.selectedDates[this.selectedDates.length - 1]
|
date = this.lastSelectedDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
date.setHours(h);
|
date.setHours(h);
|
||||||
@ -1091,7 +1102,6 @@ var Datepicker;
|
|||||||
if (!selected) {
|
if (!selected) {
|
||||||
this.selectDate(date);
|
this.selectDate(date);
|
||||||
} else {
|
} else {
|
||||||
this.selectedDates[selectedDates.length - 1] = date;
|
|
||||||
this._setInputValue();
|
this._setInputValue();
|
||||||
this._triggerOnChange();
|
this._triggerOnChange();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -64,12 +64,13 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
_setDefaultMinMaxTime: function () {
|
_setDefaultMinMaxTime: function () {
|
||||||
var maxHours = 23;
|
var maxHours = 23,
|
||||||
|
opts = this.opts;
|
||||||
|
|
||||||
this.minHours = this.opts.minHours;
|
this.minHours = opts.minHours < 0 || opts.minHours > maxHours ? 0 : opts.minHours;
|
||||||
this.minMinutes = this.opts.minMinutes;
|
this.minMinutes = opts.minMinutes < 0 || opts.minMinutes > 59 ? 0 : opts.minMinutes;
|
||||||
this.maxHours = this.opts.maxHours > maxHours ? maxHours : this.opts.maxHours;
|
this.maxHours = opts.maxHours < 0 || opts.maxHours > maxHours ? maxHours : opts.maxHours;
|
||||||
this.maxMinutes = this.opts.maxMinutes > 59 ? 59 : this.opts.maxMinutes;
|
this.maxMinutes = opts.maxMinutes < 0 || opts.maxMinutes > 59 ? 59 : opts.maxMinutes;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -139,19 +140,26 @@
|
|||||||
}).change();
|
}).change();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets minHours, minMinutes etc. from date. If date is not passed, than sets
|
||||||
|
* values from options
|
||||||
|
* @param [date] {object} - Date object, to get values from
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
_handleDate: function (date) {
|
_handleDate: function (date) {
|
||||||
if (datepicker.isSame(date, this.d.opts.minDate)) {
|
this._setDefaultMinMaxTime();
|
||||||
this._setMinTimeFromDate(this.d.opts.minDate);
|
|
||||||
} else if (datepicker.isSame(date, this.d.opts.maxDate)) {
|
if (date) {
|
||||||
this._setMaxTimeFromDate(this.d.opts.maxDate);
|
if (datepicker.isSame(date, this.d.opts.minDate)) {
|
||||||
} else {
|
this._setMinTimeFromDate(this.d.opts.minDate);
|
||||||
this._setDefaultMinMaxTime();
|
} else if (datepicker.isSame(date, this.d.opts.maxDate)) {
|
||||||
|
this._setMaxTimeFromDate(this.d.opts.maxDate);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this._validateHoursMinutes();
|
this._validateHoursMinutes();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
// Events
|
// Events
|
||||||
// -------------------------------------------------
|
// -------------------------------------------------
|
||||||
|
|
||||||
@ -169,6 +177,5 @@
|
|||||||
this._updateRanges();
|
this._updateRanges();
|
||||||
this._updateCurrentTime();
|
this._updateCurrentTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
})(window, jQuery, Datepicker);
|
})(window, jQuery, Datepicker);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user