fix(date): allow default value to Date field (#3740)

This commit is contained in:
Erez Rokah 2020-05-11 17:30:28 +03:00 committed by GitHub
parent 7cc4c89539
commit 8ab2a6036b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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(); formats = this.getFormats();
defaultValue = this.getDefaultValue();
componentDidMount() { componentDidMount() {
warnDeprecated(); 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 * Set the current date as default value if no default value is provided. An
* empty string means the value is intentionally blank. * empty string means the value is intentionally blank.
*/ */
if (!value && value !== '') { if (value === undefined) {
setTimeout(() => { setTimeout(() => {
this.handleChange(new Date()); this.handleChange(this.defaultValue === undefined ? new Date() : this.defaultValue);
}, 0); }, 0);
} }
} }