Skip to content

Commit

Permalink
allow empty default date value
Browse files Browse the repository at this point in the history
  • Loading branch information
erquhart committed Nov 28, 2017
1 parent c87660d commit 14f8bc9
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/components/Widgets/DateControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ import moment from 'moment';

export default class DateControl extends React.Component {
componentDidMount() {
const { value, field, onChange } = this.props;
const { value, field } = this.props;
this.format = field.get('format');
if (!value) {

/**
* Set the current date as default value if no default value is provided.
*/
if (value === undefined) {
this.handleChange(new Date());
}
}
Expand All @@ -16,7 +20,7 @@ export default class DateControl extends React.Component {
const newValue = this.format
? moment(datetime).format(this.format)
: datetime;
onChange(newValue);
this.props.onChange(newValue);
};

render() {
Expand Down

0 comments on commit 14f8bc9

Please sign in to comment.