Skip to content

Commit cc4ddac

Browse files
committed
onChange & onBlur argument is now a moment.js object
1 parent d3f4b34 commit cc4ddac

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

DateTime.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ var Datetime = React.createClass({
106106

107107
onChange: function(event) {
108108
var value = event.target == null ? event : event.target.value,
109-
localMoment = this.localMoment( date )
109+
localMoment = this.localMoment( value )
110110
;
111111

112112
if (localMoment.isValid()) {
@@ -119,7 +119,7 @@ var Datetime = React.createClass({
119119
return this.setState({
120120
inputValue: value
121121
}, function() {
122-
return this.props.onChange( localMoment.toDate() );
122+
return this.props.onChange( localMoment );
123123
});
124124
},
125125

@@ -295,4 +295,7 @@ var Datetime = React.createClass({
295295
}
296296
});
297297

298+
// Make moment accessible through the Datetime class
299+
Datetime.moment = moment;
300+
298301
module.exports = Datetime;

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ API
3131

3232
| Name | Type | Default | Description |
3333
| ------------ | ------- | ------- | ----------- |
34-
| **date** | Date | new Date() | Represents the inital dateTime, this string is then parsed by moment.js |
34+
| **date** | Date | new Date() | Represents the inital dateTime, this prop is parsed by moment.js, so it is possible to use a date string. |
3535
| **dateFormat** | string | Locale default | Defines the format moment.js should use to parse and output the date. The default is only set if there is not `timeFormat` defined. |
3636
| **timeFormat** | string | Locale default | Defines the format moment.js should use to parse and output the time. The default is only set if there is not `dateFormat` defined. |
3737
| **input** | boolean | true | Wether to show an input field to edit the date manually. |
3838
| **locale** | string | null | Manually set the locale for the react-datetime instance. Moment.js locale needs to be loaded to be used, see [i18n docs](#i18n).
39-
| **onChange** | function | empty functin | Callback trigger when the date changes. The callback receives the selected `Date` object as only parameter. |
40-
| **onBlur** | function | empty function | Callback trigger for when the user clicks outside of the input, simulating a regular onBlur. The callback receives the selected `Date` object as only parameter. |
39+
| **onChange** | function | empty functin | Callback trigger when the date changes. The callback receives the selected `moment` object as only parameter. |
40+
| **onBlur** | function | empty function | Callback trigger for when the user clicks outside of the input, simulating a regular onBlur. The callback receives the selected `moment` object as only parameter. |
4141
| **viewMode** | string or number | 'days' | The default view to display when the picker is shown. ('years', 'months', 'days', 'time') |
4242
| **inputProps** | object | undefined | Defines additional attributes for the input element of the component. |
4343
| **minDate** | moment | undefined | The earliest date allowed for entry in the calendar view. |

0 commit comments

Comments
 (0)