From 556e0d56aa623219d4f0f3be93bd2ba410e6596f Mon Sep 17 00:00:00 2001 From: Martin Jagodic Date: Fri, 30 Aug 2024 13:44:20 +0200 Subject: [PATCH] fix: trigger change if default is {{now}} (#7272) --- .../decap-cms-widget-datetime/src/DateTimeControl.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/decap-cms-widget-datetime/src/DateTimeControl.js b/packages/decap-cms-widget-datetime/src/DateTimeControl.js index dde5f776ce23..ae0a636c822a 100644 --- a/packages/decap-cms-widget-datetime/src/DateTimeControl.js +++ b/packages/decap-cms-widget-datetime/src/DateTimeControl.js @@ -62,6 +62,13 @@ class DateTimeControl extends React.Component { isDisabled: false, }; + componentDidMount() { + const { value } = this.props; + if (value === '{{now}}') { + this.handleChange(this.getNow()); + } + } + isUtc = this.props.field.get('picker_utc') || false; escapeZ(str) { @@ -123,10 +130,6 @@ class DateTimeControl extends React.Component { if (value === '') return value; const { format, inputFormat } = this.getFormat(); - if (typeof value === 'string' && value?.replace(/\s+/g, '') === '{{now}}') { - return this.getNow(); - } - const inputValue = this.isUtc ? dayjs.utc(value, format).format(inputFormat) : dayjs(value, format).format(inputFormat);