Commit 2b95c799 by Ari Rizzitano

fix(asinput): override state value when props value changes

parent 74713fe6
...@@ -38,6 +38,7 @@ const asInput = (WrappedComponent, labelFirst = true) => { ...@@ -38,6 +38,7 @@ const asInput = (WrappedComponent, labelFirst = true) => {
const id = this.props.id ? this.props.id : newId('asInput'); const id = this.props.id ? this.props.id : newId('asInput');
this.state = { this.state = {
id, id,
value: this.props.value,
isValid: true, isValid: true,
describedBy: [], describedBy: [],
errorId: `error-${id}`, errorId: `error-${id}`,
...@@ -45,6 +46,14 @@ const asInput = (WrappedComponent, labelFirst = true) => { ...@@ -45,6 +46,14 @@ const asInput = (WrappedComponent, labelFirst = true) => {
}; };
} }
componentWillReceiveProps(nextProps) {
if (nextProps.value !== this.props.value) {
this.setState({
value: nextProps.value,
});
}
}
getDescriptions() { getDescriptions() {
// possible future work: multiple feedback msgs? // possible future work: multiple feedback msgs?
const errorId = `error-${this.state.id}`; const errorId = `error-${this.state.id}`;
...@@ -96,6 +105,7 @@ const asInput = (WrappedComponent, labelFirst = true) => { ...@@ -96,6 +105,7 @@ const asInput = (WrappedComponent, labelFirst = true) => {
} }
handleChange(event) { handleChange(event) {
this.setState({ value: event.target.value });
this.props.onChange( this.props.onChange(
event.target.type === 'checkbox' ? event.target.checked : event.target.value, event.target.type === 'checkbox' ? event.target.checked : event.target.value,
this.props.name, this.props.name,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment