From 782c386d3e63c60d1f964a6005e66041b18424b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A1ssio=20Zen?= Date: Thu, 1 Dec 2016 16:28:33 -0200 Subject: [PATCH] Widget should set default values through onChange Otherwise, default value may not get persisted --- src/components/Widgets/DateControl.js | 10 ++++++++-- src/components/Widgets/DateTimeControl.js | 12 +++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/components/Widgets/DateControl.js b/src/components/Widgets/DateControl.js index b0170ee7..edd918f2 100644 --- a/src/components/Widgets/DateControl.js +++ b/src/components/Widgets/DateControl.js @@ -2,6 +2,12 @@ import React, { PropTypes } from 'react'; import DateTime from 'react-datetime'; export default class DateControl extends React.Component { + componentDidMount() { + if (!this.props.value) { + this.props.onChange(new Date()); + } + } + handleChange = (datetime) => { this.props.onChange(datetime); }; @@ -9,7 +15,7 @@ export default class DateControl extends React.Component { render() { return (); } @@ -17,5 +23,5 @@ export default class DateControl extends React.Component { DateControl.propTypes = { onChange: PropTypes.func.isRequired, - value: PropTypes.object, + value: PropTypes.object, // eslint-disable-line }; diff --git a/src/components/Widgets/DateTimeControl.js b/src/components/Widgets/DateTimeControl.js index 290819b4..7a690f9c 100644 --- a/src/components/Widgets/DateTimeControl.js +++ b/src/components/Widgets/DateTimeControl.js @@ -2,16 +2,22 @@ import React, { PropTypes } from 'react'; import DateTime from 'react-datetime'; export default class DateTimeControl extends React.Component { - handleChange = datetime => { + componentDidMount() { + if (!this.props.value) { + this.props.onChange(new Date()); + } + } + + handleChange = (datetime) => { this.props.onChange(datetime); }; render() { - return ; + return ; } } DateTimeControl.propTypes = { onChange: PropTypes.func.isRequired, - value: PropTypes.object, + value: PropTypes.object, // eslint-disable-line };