diff --git a/client/src/views/fields/date.js b/client/src/views/fields/date.js index d9266ef841..6238a946b2 100644 --- a/client/src/views/fields/date.js +++ b/client/src/views/fields/date.js @@ -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; diff --git a/client/src/views/fields/datetime.js b/client/src/views/fields/datetime.js index 2c9e8763a0..a23811c182 100644 --- a/client/src/views/fields/datetime.js +++ b/client/src/views/fields/datetime.js @@ -360,6 +360,8 @@ class DatetimeFieldView extends DateFieldView { return data; } + + onAfterChange() {} } export default DatetimeFieldView;