date change on after change only for date

This commit is contained in:
Yuri Kuznetsov
2025-06-29 13:25:38 +03:00
parent a01f3333b3
commit d479408fea
2 changed files with 25 additions and 13 deletions
+23 -13
View File
@@ -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;
+2
View File
@@ -360,6 +360,8 @@ class DatetimeFieldView extends DateFieldView {
return data;
}
onAfterChange() {}
}
export default DatetimeFieldView;