Skip to content

Commit 254cdb5

Browse files
committed
Make sure switching AM/PM works
1 parent fdbba70 commit 254cdb5

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

src/DateTimeField.jsx

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,16 @@ DateTimeField = React.createClass({
5353
}
5454
},
5555
onChange: function(event) {
56-
if (moment(event.target.value, this.props.inputFormat, true).isValid()) {
56+
var value = event.target == null ? event : event.target.value;
57+
if (moment(value, this.props.inputFormat, true).isValid()) {
5758
this.setState({
58-
selectedDate: moment(event.target.value, this.props.inputFormat, true),
59-
viewDate: moment(event.target.value, this.props.inputFormat, true).startOf("month")
59+
selectedDate: moment(value, this.props.inputFormat, true),
60+
viewDate: moment(value, this.props.inputFormat, true).startOf("month")
6061
});
6162
}
6263

6364
return this.setState({
64-
inputValue: event.target.value
65+
inputValue: value
6566
}, function() {
6667
return this.props.onChange(moment(this.state.inputValue, this.props.inputFormat, true).format(this.props.format));
6768
});
@@ -170,13 +171,9 @@ DateTimeField = React.createClass({
170171
},
171172
togglePeriod: function() {
172173
if (this.state.selectedDate.hour() > 12) {
173-
return this.setState({
174-
selectedDate: this.state.selectedDate.clone().subtract(12, 'hours')
175-
});
174+
return this.onChange(this.state.selectedDate.clone().subtract(12, 'hours').format(this.props.inputFormat));
176175
} else {
177-
return this.setState({
178-
selectedDate: this.state.selectedDate.clone().add(12, 'hours')
179-
});
176+
return this.onChange(this.state.selectedDate.clone().add(12, 'hours').format(this.props.inputFormat));
180177
}
181178
},
182179
togglePicker: function() {

0 commit comments

Comments
 (0)