date change on after change only for date
This commit is contained in:
@@ -144,19 +144,7 @@ class DateFieldView extends BaseFieldView {
|
||||
|
||||
// Timeout prevents the picker popping one when the duration field adjusts the date end.
|
||||
setTimeout(() => {
|
||||
/** @type {string} */
|
||||
const from = this.model.attributes[this.params.after];
|
||||
/** @type {string} */
|
||||
const currentValue = this.model.attributes[this.name];
|
||||
|
||||
if (
|
||||
from &&
|
||||
currentValue &&
|
||||
this.getDateTime().toMomentDate(currentValue)
|
||||
.isBefore(this.getDateTime().toMomentDate(from))
|
||||
) {
|
||||
this.model.set(this.name, from);
|
||||
}
|
||||
this.onAfterChange();
|
||||
|
||||
this.datepicker.setStartDate(this.getStartDateForDatePicker());
|
||||
}, 100);
|
||||
@@ -582,6 +570,28 @@ class DateFieldView extends BaseFieldView {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @since 9.2.0
|
||||
*/
|
||||
onAfterChange() {
|
||||
/** @type {string} */
|
||||
const from = this.model.attributes[this.params.after];
|
||||
/** @type {string} */
|
||||
const currentValue = this.model.attributes[this.name];
|
||||
|
||||
if (!from || !currentValue || from.length !== currentValue.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
this.getDateTime().toMomentDate(currentValue)
|
||||
.isBefore(this.getDateTime().toMomentDate(from))
|
||||
) {
|
||||
this.model.set(this.name, from);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default DateFieldView;
|
||||
|
||||
@@ -360,6 +360,8 @@ class DatetimeFieldView extends DateFieldView {
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
onAfterChange() {}
|
||||
}
|
||||
|
||||
export default DatetimeFieldView;
|
||||
|
||||
Reference in New Issue
Block a user