From 688332410c2fa5b0a6401cb640d3a8d3bdc00cfb Mon Sep 17 00:00:00 2001 From: Mathias Biilmann Christensen Date: Sun, 26 Nov 2017 11:30:53 -0800 Subject: [PATCH] Keep old behevior if no format attribute is set on date widgets --- src/components/Widgets/DateControl.js | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/components/Widgets/DateControl.js b/src/components/Widgets/DateControl.js index ff88ca2c..5ec741eb 100644 --- a/src/components/Widgets/DateControl.js +++ b/src/components/Widgets/DateControl.js @@ -4,13 +4,28 @@ import DateTime from 'react-datetime'; import moment from 'moment'; function format(format, value) { - return moment(value).format(format || moment.defaultFormat); + if (format) { + return moment(value).format(format || moment.defaultFormat); + } + return value; +} + +function toDate(format, value) { + if (format) { + return moment(value, format); + } + return value; } export default class DateTimeControl extends React.Component { componentDidMount() { - if (!this.props.value) { - this.props.onChange(format(this.props.field.get('format'), new Date())); + const {value, field, onChange} = this.props; + if (!value) { + if (field.get('format')) { + onChange(format(field.get('format'), new Date())); + } else { + onChange(new Date()); + } } } @@ -22,7 +37,7 @@ export default class DateTimeControl extends React.Component { return ( ); }