mirror of
https://github.com/ascribe/onion.git
synced 2024-12-22 09:23:13 +01:00
Merge pull request #82 from ascribe/fix-input-date
Fix InputDate's initial evaluation of defaultValue
This commit is contained in:
commit
eaaaa3bb76
@ -156,7 +156,7 @@ let Form = React.createClass({
|
||||
|
||||
for(let ref in this.refs) {
|
||||
if(this.refs[ref] && typeof this.refs[ref].handleSuccess === 'function'){
|
||||
this.refs[ref].handleSuccess();
|
||||
this.refs[ref].handleSuccess(response);
|
||||
}
|
||||
}
|
||||
this.setState({
|
||||
|
@ -171,7 +171,7 @@ let LoanForm = React.createClass({
|
||||
editable={!gallery}
|
||||
overrideForm={!!gallery}>
|
||||
<input
|
||||
value={gallery}
|
||||
defaultValue={gallery}
|
||||
type="text"
|
||||
placeholder={getLangText('Gallery/exhibition (optional)')}/>
|
||||
</Property>
|
||||
|
@ -17,10 +17,7 @@ let InputDate = React.createClass({
|
||||
},
|
||||
|
||||
getInitialState() {
|
||||
return {
|
||||
value: null,
|
||||
value_moment: null
|
||||
};
|
||||
return this.getStateFromMoment(this.props.defaultValue);
|
||||
},
|
||||
|
||||
// InputDate needs to support setting a defaultValue from outside.
|
||||
@ -28,20 +25,30 @@ let InputDate = React.createClass({
|
||||
// to the outer Property
|
||||
componentWillReceiveProps(nextProps) {
|
||||
if(!this.state.value && !this.state.value_moment && nextProps.defaultValue) {
|
||||
this.handleChange(this.props.defaultValue);
|
||||
this.handleChange(nextProps.defaultValue);
|
||||
}
|
||||
},
|
||||
|
||||
handleChange(date) {
|
||||
let formattedDate = date.format('YYYY-MM-DD');
|
||||
this.setState({
|
||||
value: formattedDate,
|
||||
value_moment: date
|
||||
});
|
||||
getStateFromMoment(date) {
|
||||
const state = {};
|
||||
|
||||
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({
|
||||
target: {
|
||||
value: formattedDate
|
||||
value: newState.value
|
||||
}
|
||||
});
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user