1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-23 01:39:36 +01:00

Fix defaultValue not being initially set for InputDate

This commit is contained in:
Brett Sun 2015-12-18 15:00:37 +01:00
parent 0f8094ef55
commit db2b027656

View File

@ -17,10 +17,7 @@ let InputDate = React.createClass({
}, },
getInitialState() { getInitialState() {
return { return this.getStateFromMoment(this.props.defaultValue);
value: null,
value_moment: null
};
}, },
// InputDate needs to support setting a defaultValue from outside. // InputDate needs to support setting a defaultValue from outside.
@ -28,20 +25,30 @@ let InputDate = React.createClass({
// to the outer Property // to the outer Property
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
if(!this.state.value && !this.state.value_moment && nextProps.defaultValue) { if(!this.state.value && !this.state.value_moment && nextProps.defaultValue) {
this.handleChange(this.props.defaultValue); this.handleChange(nextProps.defaultValue);
} }
}, },
handleChange(date) { getStateFromMoment(date) {
let formattedDate = date.format('YYYY-MM-DD'); const state = {};
this.setState({
value: formattedDate,
value_moment: date
});
if (date) {
state.value = date.format('YYYY-MM-DD');
state.value_moment = date;
}
return state;
},
handleChange(date) {
const newState = this.getStateFromMoment(date);
this.setState(newState);
// Propagate change up by faking event
this.props.onChange({ this.props.onChange({
target: { target: {
value: formattedDate value: newState.value
} }
}); });
}, },