Skip to content

Commit

Permalink
Added option to hide Today button in Date field (#4869)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcin-lawrowski authored and autoboxer committed Dec 5, 2018
1 parent c7db2a3 commit a202478
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
10 changes: 7 additions & 3 deletions fields/types/date/DateField.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module.exports = Field.create({
note: React.PropTypes.string,
onChange: React.PropTypes.func,
path: React.PropTypes.string,
todayButton: React.PropTypes.bool,
value: React.PropTypes.string,
},

Expand Down Expand Up @@ -85,9 +86,12 @@ module.exports = Field.create({
value={value}
/>
</Section>
<Section>
<Button onClick={this.setToday}>Today</Button>
</Section>
{
this.props.todayButton
&& <Section>
<Button onClick={this.setToday}>Today</Button>
</Section>
}
</Group>
);
},
Expand Down
3 changes: 2 additions & 1 deletion fields/types/date/DateType.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ function date (list, path, options) {
this._nativeType = Date;
this._underscoreMethods = ['format', 'moment', 'parse'];
this._fixedSize = 'medium';
this._properties = ['formatString', 'yearRange', 'isUTC', 'inputFormat'];
this._properties = ['formatString', 'yearRange', 'isUTC', 'inputFormat', 'todayButton'];
this.parseFormatString = options.inputFormat || 'YYYY-MM-DD';
this.formatString = (options.format === false) ? false : (options.format || 'Do MMM YYYY');

this.yearRange = options.yearRange;
this.isUTC = options.utc || false;
this.todayButton = typeof options.todayButton !== 'undefined' ? options.todayButton : true;

/*
* This offset is used to determine whether or not a stored date is probably corrupted or not.
Expand Down
6 changes: 6 additions & 0 deletions fields/types/date/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ Defaults to 'Do MMM YYYY'

See the [momentjs format docs](http://momentjs.com/docs/#/displaying/format/) for information on the supported formats and options.

* `todayButton` `Boolean`

Determines if the Today button will be displayed.

Defaults to 'true'

## Methods

### `format(formatString)`
Expand Down

0 comments on commit a202478

Please sign in to comment.