mirror of
https://github.com/frappe/air-datepicker.git
synced 2026-01-14 11:01:22 +08:00
changed handling of selection of already selected dates, closes #105
Now for selecting single date in range mode, `toggleSelected` must be `false`
This commit is contained in:
parent
e8facd22b0
commit
701df87dbe
48
dist/js/datepicker.js
vendored
48
dist/js/datepicker.js
vendored
@ -1083,6 +1083,30 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_handleAlreadySelectedDates: function (alreadySelected, selectedDate) {
|
||||||
|
if (this.opts.range) {
|
||||||
|
if (!this.opts.toggleSelected) {
|
||||||
|
// Add possibility to select same date when range is true
|
||||||
|
if (this.selectedDates.length != 2) {
|
||||||
|
this._trigger('clickCell', selectedDate);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.removeDate(selectedDate);
|
||||||
|
}
|
||||||
|
} else if (this.opts.toggleSelected){
|
||||||
|
this.removeDate(selectedDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Change last selected date to be able to change time when clicking on this cell
|
||||||
|
if (!this.opts.toggleSelected) {
|
||||||
|
this.lastSelectedDate = alreadySelected;
|
||||||
|
if (this.opts.timepicker) {
|
||||||
|
this.timepicker._setTime(alreadySelected);
|
||||||
|
this.timepicker.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
_onShowEvent: function (e) {
|
_onShowEvent: function (e) {
|
||||||
if (!this.visible) {
|
if (!this.visible) {
|
||||||
this.show();
|
this.show();
|
||||||
@ -1157,9 +1181,9 @@
|
|||||||
this.focused.setMinutes(this.timepicker.minutes);
|
this.focused.setMinutes(this.timepicker.minutes);
|
||||||
}
|
}
|
||||||
this.selectDate(this.focused);
|
this.selectDate(this.focused);
|
||||||
} else if (alreadySelected && this.opts.toggleSelected){
|
return;
|
||||||
this.removeDate(this.focused);
|
|
||||||
}
|
}
|
||||||
|
this._handleAlreadySelectedDates(alreadySelected, this.focused)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1755,27 +1779,11 @@
|
|||||||
|
|
||||||
if (!alreadySelected) {
|
if (!alreadySelected) {
|
||||||
dp._trigger('clickCell', selectedDate);
|
dp._trigger('clickCell', selectedDate);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (alreadySelected && this.opts.range) {
|
dp._handleAlreadySelectedDates.bind(dp, alreadySelected, selectedDate)();
|
||||||
// Add possibility to select same date when range is true
|
|
||||||
if (dp.selectedDates.length != 2 && !this.opts.toggleSelected || this.opts.toggleSelected) {
|
|
||||||
dp._trigger('clickCell', selectedDate);
|
|
||||||
// Change last selected date to be able to change time on last date
|
|
||||||
dp.lastSelectedDate = alreadySelected;
|
|
||||||
}
|
|
||||||
} else if (alreadySelected && this.opts.toggleSelected){
|
|
||||||
dp.removeDate(selectedDate);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Change last selected date to be able to change time when clicking on this cell
|
|
||||||
if (alreadySelected && !this.opts.toggleSelected) {
|
|
||||||
dp.lastSelectedDate = alreadySelected;
|
|
||||||
if (dp.opts.timepicker) {
|
|
||||||
dp.timepicker._setTime(alreadySelected);
|
|
||||||
dp.timepicker.update();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_onClickCell: function (e) {
|
_onClickCell: function (e) {
|
||||||
|
|||||||
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
@ -293,27 +293,11 @@
|
|||||||
|
|
||||||
if (!alreadySelected) {
|
if (!alreadySelected) {
|
||||||
dp._trigger('clickCell', selectedDate);
|
dp._trigger('clickCell', selectedDate);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (alreadySelected && this.opts.range) {
|
dp._handleAlreadySelectedDates.bind(dp, alreadySelected, selectedDate)();
|
||||||
// Add possibility to select same date when range is true
|
|
||||||
if (dp.selectedDates.length != 2 && !this.opts.toggleSelected || this.opts.toggleSelected) {
|
|
||||||
dp._trigger('clickCell', selectedDate);
|
|
||||||
// Change last selected date to be able to change time on last date
|
|
||||||
dp.lastSelectedDate = alreadySelected;
|
|
||||||
}
|
|
||||||
} else if (alreadySelected && this.opts.toggleSelected){
|
|
||||||
dp.removeDate(selectedDate);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Change last selected date to be able to change time when clicking on this cell
|
|
||||||
if (alreadySelected && !this.opts.toggleSelected) {
|
|
||||||
dp.lastSelectedDate = alreadySelected;
|
|
||||||
if (dp.opts.timepicker) {
|
|
||||||
dp.timepicker._setTime(alreadySelected);
|
|
||||||
dp.timepicker.update();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_onClickCell: function (e) {
|
_onClickCell: function (e) {
|
||||||
|
|||||||
@ -1083,6 +1083,30 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_handleAlreadySelectedDates: function (alreadySelected, selectedDate) {
|
||||||
|
if (this.opts.range) {
|
||||||
|
if (!this.opts.toggleSelected) {
|
||||||
|
// Add possibility to select same date when range is true
|
||||||
|
if (this.selectedDates.length != 2) {
|
||||||
|
this._trigger('clickCell', selectedDate);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.removeDate(selectedDate);
|
||||||
|
}
|
||||||
|
} else if (this.opts.toggleSelected){
|
||||||
|
this.removeDate(selectedDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Change last selected date to be able to change time when clicking on this cell
|
||||||
|
if (!this.opts.toggleSelected) {
|
||||||
|
this.lastSelectedDate = alreadySelected;
|
||||||
|
if (this.opts.timepicker) {
|
||||||
|
this.timepicker._setTime(alreadySelected);
|
||||||
|
this.timepicker.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
_onShowEvent: function (e) {
|
_onShowEvent: function (e) {
|
||||||
if (!this.visible) {
|
if (!this.visible) {
|
||||||
this.show();
|
this.show();
|
||||||
@ -1157,9 +1181,9 @@
|
|||||||
this.focused.setMinutes(this.timepicker.minutes);
|
this.focused.setMinutes(this.timepicker.minutes);
|
||||||
}
|
}
|
||||||
this.selectDate(this.focused);
|
this.selectDate(this.focused);
|
||||||
} else if (alreadySelected && this.opts.toggleSelected){
|
return;
|
||||||
this.removeDate(this.focused);
|
|
||||||
}
|
}
|
||||||
|
this._handleAlreadySelectedDates(alreadySelected, this.focused)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user