From 8ab2a6036be99c397c7d2fcb4ad3ebaeba549546 Mon Sep 17 00:00:00 2001 From: Erez Rokah Date: Mon, 11 May 2020 17:30:28 +0300 Subject: [PATCH] fix(date): allow default value to Date field (#3740) --- packages/netlify-cms-widget-date/src/DateControl.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/netlify-cms-widget-date/src/DateControl.js b/packages/netlify-cms-widget-date/src/DateControl.js index 37c5a50b..497ff837 100644 --- a/packages/netlify-cms-widget-date/src/DateControl.js +++ b/packages/netlify-cms-widget-date/src/DateControl.js @@ -50,7 +50,14 @@ export default class DateControl extends React.Component { }; } + getDefaultValue() { + const { field } = this.props; + const defaultValue = field.get('default'); + return defaultValue; + } + formats = this.getFormats(); + defaultValue = this.getDefaultValue(); componentDidMount() { warnDeprecated(); @@ -60,9 +67,9 @@ export default class DateControl extends React.Component { * Set the current date as default value if no default value is provided. An * empty string means the value is intentionally blank. */ - if (!value && value !== '') { + if (value === undefined) { setTimeout(() => { - this.handleChange(new Date()); + this.handleChange(this.defaultValue === undefined ? new Date() : this.defaultValue); }, 0); } }