Skip to content

Commit

Permalink
fix: trigger change if default is {{now}} (#7272)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinjagodic committed Aug 30, 2024
1 parent 64d91b8 commit 556e0d5
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/decap-cms-widget-datetime/src/DateTimeControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 556e0d5

Please sign in to comment.