mirror of
https://github.com/frappe/air-datepicker.git
synced 2026-01-14 11:01:22 +08:00
improve selectDate method by adding time validation, add some timepicker tests
This commit is contained in:
parent
8c4b94547a
commit
2711ba3c04
38
dist/js/datepicker.js
vendored
38
dist/js/datepicker.js
vendored
@ -160,6 +160,7 @@ var Datepicker;
|
||||
}
|
||||
this.$datepicker.on('mousedown', this._onMouseDownDatepicker.bind(this));
|
||||
this.$datepicker.on('mouseup', this._onMouseUpDatepicker.bind(this));
|
||||
this.$el.on('clickCell.adp', this._onClickCell.bind(this));
|
||||
}
|
||||
|
||||
if (this.opts.classes) {
|
||||
@ -416,12 +417,21 @@ var Datepicker;
|
||||
|
||||
this.lastSelectedDate = date;
|
||||
|
||||
// Set new time values from Date
|
||||
if (this.timepicker) {
|
||||
this.timepicker.hours = date.getHours();
|
||||
this.timepicker.minutes = date.getMinutes();
|
||||
}
|
||||
|
||||
// On this step timepicker will set valid values in it's instance
|
||||
_this._trigger('selectDate', date);
|
||||
|
||||
//TODO стоит убрать в timepicker.js
|
||||
// Set correct time values after timepicker's validation
|
||||
// Prevent from setting hours or minutes which values are lesser then `min` value or
|
||||
// greater then `max` value
|
||||
if (this.timepicker) {
|
||||
date.setHours(this.timepicker.hours);
|
||||
date.setMinutes(this.timepicker.minutes);
|
||||
date.setHours(this.timepicker.hours)
|
||||
date.setMinutes(this.timepicker.minutes)
|
||||
}
|
||||
|
||||
if (_this.view == 'days') {
|
||||
@ -1140,6 +1150,14 @@ var Datepicker;
|
||||
}
|
||||
},
|
||||
|
||||
_onClickCell: function (e, date) {
|
||||
if (this.timepicker) {
|
||||
date.setHours(this.timepicker.hours);
|
||||
date.setMinutes(this.timepicker.minutes);
|
||||
}
|
||||
this.selectDate(date);
|
||||
},
|
||||
|
||||
set focused(val) {
|
||||
if (!val && this.focused) {
|
||||
var $cell = this._getCell(this.focused);
|
||||
@ -1632,7 +1650,7 @@ var Datepicker;
|
||||
alreadySelected = this.d._isSelected(selectedDate, this.d.cellType);
|
||||
|
||||
if (!alreadySelected) {
|
||||
this.d.selectDate(selectedDate);
|
||||
this.d._trigger('clickCell', selectedDate);
|
||||
} else if (alreadySelected && this.opts.toggleSelected){
|
||||
this.d.removeDate(selectedDate);
|
||||
}
|
||||
@ -1862,7 +1880,7 @@ var Datepicker;
|
||||
* are out of range sets valid values.
|
||||
* @private
|
||||
*/
|
||||
_validateHoursMinutes: function () {
|
||||
_validateHoursMinutes: function (date) {
|
||||
if (this.hours < this.minHours) {
|
||||
this.hours = this.minHours;
|
||||
} else if (this.hours > this.maxHours) {
|
||||
@ -1946,7 +1964,12 @@ var Datepicker;
|
||||
}
|
||||
}
|
||||
|
||||
this._validateHoursMinutes();
|
||||
this._validateHoursMinutes(date);
|
||||
},
|
||||
|
||||
update: function () {
|
||||
this._updateRanges();
|
||||
this._updateCurrentTime();
|
||||
},
|
||||
|
||||
/**
|
||||
@ -2004,8 +2027,7 @@ var Datepicker;
|
||||
|
||||
_onSelectDate: function (e, data) {
|
||||
this._handleDate(data);
|
||||
this._updateRanges();
|
||||
this._updateCurrentTime();
|
||||
this.update();
|
||||
},
|
||||
|
||||
set hours (val) {
|
||||
|
||||
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
@ -290,7 +290,7 @@
|
||||
alreadySelected = this.d._isSelected(selectedDate, this.d.cellType);
|
||||
|
||||
if (!alreadySelected) {
|
||||
this.d.selectDate(selectedDate);
|
||||
this.d._trigger('clickCell', selectedDate);
|
||||
} else if (alreadySelected && this.opts.toggleSelected){
|
||||
this.d.removeDate(selectedDate);
|
||||
}
|
||||
|
||||
@ -160,6 +160,7 @@ var Datepicker;
|
||||
}
|
||||
this.$datepicker.on('mousedown', this._onMouseDownDatepicker.bind(this));
|
||||
this.$datepicker.on('mouseup', this._onMouseUpDatepicker.bind(this));
|
||||
this.$el.on('clickCell.adp', this._onClickCell.bind(this));
|
||||
}
|
||||
|
||||
if (this.opts.classes) {
|
||||
@ -416,12 +417,21 @@ var Datepicker;
|
||||
|
||||
this.lastSelectedDate = date;
|
||||
|
||||
// Set new time values from Date
|
||||
if (this.timepicker) {
|
||||
this.timepicker.hours = date.getHours();
|
||||
this.timepicker.minutes = date.getMinutes();
|
||||
}
|
||||
|
||||
// On this step timepicker will set valid values in it's instance
|
||||
_this._trigger('selectDate', date);
|
||||
|
||||
//TODO стоит убрать в timepicker.js
|
||||
// Set correct time values after timepicker's validation
|
||||
// Prevent from setting hours or minutes which values are lesser then `min` value or
|
||||
// greater then `max` value
|
||||
if (this.timepicker) {
|
||||
date.setHours(this.timepicker.hours);
|
||||
date.setMinutes(this.timepicker.minutes);
|
||||
date.setHours(this.timepicker.hours)
|
||||
date.setMinutes(this.timepicker.minutes)
|
||||
}
|
||||
|
||||
if (_this.view == 'days') {
|
||||
@ -1140,6 +1150,14 @@ var Datepicker;
|
||||
}
|
||||
},
|
||||
|
||||
_onClickCell: function (e, date) {
|
||||
if (this.timepicker) {
|
||||
date.setHours(this.timepicker.hours);
|
||||
date.setMinutes(this.timepicker.minutes);
|
||||
}
|
||||
this.selectDate(date);
|
||||
},
|
||||
|
||||
set focused(val) {
|
||||
if (!val && this.focused) {
|
||||
var $cell = this._getCell(this.focused);
|
||||
|
||||
@ -70,7 +70,7 @@
|
||||
* are out of range sets valid values.
|
||||
* @private
|
||||
*/
|
||||
_validateHoursMinutes: function () {
|
||||
_validateHoursMinutes: function (date) {
|
||||
if (this.hours < this.minHours) {
|
||||
this.hours = this.minHours;
|
||||
} else if (this.hours > this.maxHours) {
|
||||
@ -154,7 +154,12 @@
|
||||
}
|
||||
}
|
||||
|
||||
this._validateHoursMinutes();
|
||||
this._validateHoursMinutes(date);
|
||||
},
|
||||
|
||||
update: function () {
|
||||
this._updateRanges();
|
||||
this._updateCurrentTime();
|
||||
},
|
||||
|
||||
/**
|
||||
@ -212,8 +217,7 @@
|
||||
|
||||
_onSelectDate: function (e, data) {
|
||||
this._handleDate(data);
|
||||
this._updateRanges();
|
||||
this._updateCurrentTime();
|
||||
this.update();
|
||||
},
|
||||
|
||||
set hours (val) {
|
||||
|
||||
@ -823,6 +823,38 @@ describe('Options', function () {
|
||||
var $time = $('.datepicker--time', dp.$datepicker);
|
||||
expect($time).to.have.length(1)
|
||||
|
||||
})
|
||||
});
|
||||
|
||||
describe('dateTimeSeparator', function () {
|
||||
it('should define separator between date string and time', function () {
|
||||
var date = new Date(2016,2,9,11,24);
|
||||
dp = $input.datepicker({
|
||||
timepicker: true,
|
||||
onSelect: function (fd, d) {
|
||||
expect(fd).to.be.equal('09.03.2016 time separator 11:24')
|
||||
},
|
||||
dateTimeSeparator: ' time separator '
|
||||
}).data('datepicker');
|
||||
|
||||
dp.selectDate(date);
|
||||
|
||||
})
|
||||
});
|
||||
|
||||
describe('timeFormat', function () {
|
||||
it('should define time format', function () {
|
||||
var date = new Date(2016,2,9,9,4);
|
||||
dp = $input.datepicker({
|
||||
timepicker: true,
|
||||
timeFormat: 'h - ii',
|
||||
onSelect: function (fd, d) {
|
||||
expect(fd).to.be.equal('09.03.2016 9 - 04')
|
||||
}
|
||||
}).data('datepicker');
|
||||
|
||||
dp.selectDate(date);
|
||||
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user