mirror of
https://github.com/frappe/air-datepicker.git
synced 2026-01-14 11:01:22 +08:00
fixed minDate using with timepicker, fixes #73
This commit is contained in:
parent
44ce4aede2
commit
4295d13027
@ -26,6 +26,10 @@ $('.my-datepicker').datepicker([options])
|
|||||||
|
|
||||||
## Change log
|
## Change log
|
||||||
|
|
||||||
|
### v2.1.0
|
||||||
|
* added possibility to select single date when `{range: true}`
|
||||||
|
* added support of 12 hours mode in `altFieldDateFormat`
|
||||||
|
|
||||||
### v2.0.2
|
### v2.0.2
|
||||||
* fixed dates array in `onSelect` callback
|
* fixed dates array in `onSelect` callback
|
||||||
|
|
||||||
|
|||||||
37
dist/js/datepicker.js
vendored
37
dist/js/datepicker.js
vendored
@ -582,7 +582,8 @@
|
|||||||
* @param {String|Number|Object} [value] - new param value
|
* @param {String|Number|Object} [value] - new param value
|
||||||
*/
|
*/
|
||||||
update: function (param, value) {
|
update: function (param, value) {
|
||||||
var len = arguments.length;
|
var len = arguments.length,
|
||||||
|
lastSelectedDate = this.lastSelectedDate;
|
||||||
|
|
||||||
if (len == 2) {
|
if (len == 2) {
|
||||||
this.opts[param] = value;
|
this.opts[param] = value;
|
||||||
@ -609,13 +610,13 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.opts.timepicker) {
|
if (this.opts.timepicker) {
|
||||||
this.timepicker._handleDate(this.lastSelectedDate);
|
if (lastSelectedDate) this.timepicker._handleDate(lastSelectedDate);
|
||||||
this.timepicker._updateRanges();
|
this.timepicker._updateRanges();
|
||||||
this.timepicker._updateCurrentTime();
|
this.timepicker._updateCurrentTime();
|
||||||
// Change hours and minutes if it's values have been changed through min/max hours/minutes
|
// Change hours and minutes if it's values have been changed through min/max hours/minutes
|
||||||
if (this.lastSelectedDate) {
|
if (lastSelectedDate) {
|
||||||
this.lastSelectedDate.setHours(this.timepicker.hours);
|
lastSelectedDate.setHours(this.timepicker.hours);
|
||||||
this.lastSelectedDate.setMinutes(this.timepicker.minutes);
|
lastSelectedDate.setMinutes(this.timepicker.minutes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1934,14 +1935,34 @@
|
|||||||
this.minutes = _date.minutes < this.minMinutes ? this.minMinutes : _date.minutes;
|
this.minutes = _date.minutes < this.minMinutes ? this.minMinutes : _date.minutes;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets minHours and minMinutes from date (usually it's a minDate)
|
||||||
|
* Also changes minMinutes if current hours are bigger then @date hours
|
||||||
|
* @param date {Date}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
_setMinTimeFromDate: function (date) {
|
_setMinTimeFromDate: function (date) {
|
||||||
this.minHours = date.getHours();
|
this.minHours = date.getHours();
|
||||||
this.minMinutes = date.getMinutes();
|
this.minMinutes = date.getMinutes();
|
||||||
|
|
||||||
|
// If, for example, min hours are 10, and current hours are 12,
|
||||||
|
// update minMinutes to default value, to be able to choose whole range of values
|
||||||
|
if (this.d.lastSelectedDate) {
|
||||||
|
if (this.d.lastSelectedDate.getHours() > date.getHours()) {
|
||||||
|
this.minMinutes = this.opts.minMinutes;
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
_setMaxTimeFromDate: function (date) {
|
_setMaxTimeFromDate: function (date) {
|
||||||
this.maxHours = date.getHours();
|
this.maxHours = date.getHours();
|
||||||
this.maxMinutes = date.getMinutes();
|
this.maxMinutes = date.getMinutes();
|
||||||
|
|
||||||
|
if (this.d.lastSelectedDate) {
|
||||||
|
if (this.d.lastSelectedDate.getHours() < date.getHours()) {
|
||||||
|
this.maxMinutes = this.opts.maxMinutes;
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
_setDefaultMinMaxTime: function () {
|
_setDefaultMinMaxTime: function () {
|
||||||
@ -2036,7 +2057,6 @@
|
|||||||
*/
|
*/
|
||||||
_handleDate: function (date) {
|
_handleDate: function (date) {
|
||||||
this._setDefaultMinMaxTime();
|
this._setDefaultMinMaxTime();
|
||||||
|
|
||||||
if (date) {
|
if (date) {
|
||||||
if (dp.isSame(date, this.d.opts.minDate)) {
|
if (dp.isSame(date, this.d.opts.minDate)) {
|
||||||
this._setMinTimeFromDate(this.d.opts.minDate);
|
this._setMinTimeFromDate(this.d.opts.minDate);
|
||||||
@ -2119,7 +2139,10 @@
|
|||||||
|
|
||||||
this[name] = $target.val();
|
this[name] = $target.val();
|
||||||
this._updateCurrentTime();
|
this._updateCurrentTime();
|
||||||
this.d._trigger('timeChange', [this.hours, this.minutes])
|
this.d._trigger('timeChange', [this.hours, this.minutes]);
|
||||||
|
|
||||||
|
this._handleDate(this.d.lastSelectedDate);
|
||||||
|
this.update()
|
||||||
},
|
},
|
||||||
|
|
||||||
_onSelectDate: function (e, data) {
|
_onSelectDate: function (e, data) {
|
||||||
|
|||||||
4
dist/js/datepicker.min.js
vendored
4
dist/js/datepicker.min.js
vendored
File diff suppressed because one or more lines are too long
@ -582,7 +582,8 @@
|
|||||||
* @param {String|Number|Object} [value] - new param value
|
* @param {String|Number|Object} [value] - new param value
|
||||||
*/
|
*/
|
||||||
update: function (param, value) {
|
update: function (param, value) {
|
||||||
var len = arguments.length;
|
var len = arguments.length,
|
||||||
|
lastSelectedDate = this.lastSelectedDate;
|
||||||
|
|
||||||
if (len == 2) {
|
if (len == 2) {
|
||||||
this.opts[param] = value;
|
this.opts[param] = value;
|
||||||
@ -609,13 +610,13 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.opts.timepicker) {
|
if (this.opts.timepicker) {
|
||||||
this.timepicker._handleDate(this.lastSelectedDate);
|
if (lastSelectedDate) this.timepicker._handleDate(lastSelectedDate);
|
||||||
this.timepicker._updateRanges();
|
this.timepicker._updateRanges();
|
||||||
this.timepicker._updateCurrentTime();
|
this.timepicker._updateCurrentTime();
|
||||||
// Change hours and minutes if it's values have been changed through min/max hours/minutes
|
// Change hours and minutes if it's values have been changed through min/max hours/minutes
|
||||||
if (this.lastSelectedDate) {
|
if (lastSelectedDate) {
|
||||||
this.lastSelectedDate.setHours(this.timepicker.hours);
|
lastSelectedDate.setHours(this.timepicker.hours);
|
||||||
this.lastSelectedDate.setMinutes(this.timepicker.minutes);
|
lastSelectedDate.setMinutes(this.timepicker.minutes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -49,14 +49,34 @@
|
|||||||
this.minutes = _date.minutes < this.minMinutes ? this.minMinutes : _date.minutes;
|
this.minutes = _date.minutes < this.minMinutes ? this.minMinutes : _date.minutes;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets minHours and minMinutes from date (usually it's a minDate)
|
||||||
|
* Also changes minMinutes if current hours are bigger then @date hours
|
||||||
|
* @param date {Date}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
_setMinTimeFromDate: function (date) {
|
_setMinTimeFromDate: function (date) {
|
||||||
this.minHours = date.getHours();
|
this.minHours = date.getHours();
|
||||||
this.minMinutes = date.getMinutes();
|
this.minMinutes = date.getMinutes();
|
||||||
|
|
||||||
|
// If, for example, min hours are 10, and current hours are 12,
|
||||||
|
// update minMinutes to default value, to be able to choose whole range of values
|
||||||
|
if (this.d.lastSelectedDate) {
|
||||||
|
if (this.d.lastSelectedDate.getHours() > date.getHours()) {
|
||||||
|
this.minMinutes = this.opts.minMinutes;
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
_setMaxTimeFromDate: function (date) {
|
_setMaxTimeFromDate: function (date) {
|
||||||
this.maxHours = date.getHours();
|
this.maxHours = date.getHours();
|
||||||
this.maxMinutes = date.getMinutes();
|
this.maxMinutes = date.getMinutes();
|
||||||
|
|
||||||
|
if (this.d.lastSelectedDate) {
|
||||||
|
if (this.d.lastSelectedDate.getHours() < date.getHours()) {
|
||||||
|
this.maxMinutes = this.opts.maxMinutes;
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
_setDefaultMinMaxTime: function () {
|
_setDefaultMinMaxTime: function () {
|
||||||
@ -151,7 +171,6 @@
|
|||||||
*/
|
*/
|
||||||
_handleDate: function (date) {
|
_handleDate: function (date) {
|
||||||
this._setDefaultMinMaxTime();
|
this._setDefaultMinMaxTime();
|
||||||
|
|
||||||
if (date) {
|
if (date) {
|
||||||
if (dp.isSame(date, this.d.opts.minDate)) {
|
if (dp.isSame(date, this.d.opts.minDate)) {
|
||||||
this._setMinTimeFromDate(this.d.opts.minDate);
|
this._setMinTimeFromDate(this.d.opts.minDate);
|
||||||
@ -234,7 +253,10 @@
|
|||||||
|
|
||||||
this[name] = $target.val();
|
this[name] = $target.val();
|
||||||
this._updateCurrentTime();
|
this._updateCurrentTime();
|
||||||
this.d._trigger('timeChange', [this.hours, this.minutes])
|
this.d._trigger('timeChange', [this.hours, this.minutes]);
|
||||||
|
|
||||||
|
this._handleDate(this.d.lastSelectedDate);
|
||||||
|
this.update()
|
||||||
},
|
},
|
||||||
|
|
||||||
_onSelectDate: function (e, data) {
|
_onSelectDate: function (e, data) {
|
||||||
|
|||||||
@ -93,6 +93,17 @@
|
|||||||
<h2>{timepicker: true}</h2>
|
<h2>{timepicker: true}</h2>
|
||||||
<input class="datepicker-here" data-timepicker="true" />
|
<input class="datepicker-here" data-timepicker="true" />
|
||||||
</div>
|
</div>
|
||||||
|
<div class="vt-tile">
|
||||||
|
<h2>{timepicker: true, minDate: new Date()}</h2>
|
||||||
|
<input class="datepicker-here" id="dp-6"/>
|
||||||
|
<script type="text/javascript">
|
||||||
|
$('#dp-6').datepicker({
|
||||||
|
minDate: new Date(),
|
||||||
|
inline: true,
|
||||||
|
timepicker: true
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</article>
|
</article>
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user