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 ( ); }