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 4c35b66
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
11 changes: 11 additions & 0 deletions docs/widgets.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,14 @@ collections:
searchFields: [name, twitterHandle]
valueField: name
```

### Date Widget / DateTime Widget

The date and datetime widgets provide date or datetime pickers when the widget is active. The resulting date string can be formatted (uses Moment.js), and accepts a default value. The initial value will be the current date unless `false` or an empty string are provided as the default value.

The following field configuration properties are specific to fields using the date or datetime widget:

Property | Accepted Values | Description
--- | --- | ---
`format` | string | format string uses Moment.js [tokens](https://momentjs.com/docs/#/parsing/string-format/)
`default` | boolean, string | can be a date string, or else an empty string - defaults to current date
9 changes: 7 additions & 2 deletions src/components/Widgets/DateControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ export default class DateControl extends React.Component {
componentDidMount() {
const { value, field, onChange } = this.props;
this.format = field.get('format');
if (!value) {

/**
* Set the current date as default value if no default value is provided. An
* empty string means the value is intentionally blank.
*/
if (!value && value !== '') {
this.handleChange(new Date());
}
}
Expand All @@ -16,7 +21,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 4c35b66

Please sign in to comment.