Skip to content

Commit

Permalink
Merge pull request #174 from astonm/formsy-text-setvalue
Browse files Browse the repository at this point in the history
Use FormsyText internal _value to allow external setValue calls
  • Loading branch information
Ryan B. Blakeley committed Nov 24, 2016
2 parents c4b2219 + 4091116 commit 89f4e26
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/FormsyText.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ const FormsyText = React.createClass({

mixins: [Formsy.Mixin],

getInitialState() {
const value = this.controlledValue();
return { value };
},

componentWillMount() {
this.setValue(this.controlledValue());
Expand All @@ -39,7 +35,7 @@ const FormsyText = React.createClass({
const isValid = this.isValidValue(value);

if (isValueChanging || this.props.defaultValue === this.getValue()) {
this.setState({ value, isValid });
this.setState({ isValid });
this.setValue(value);
}
}
Expand All @@ -52,7 +48,7 @@ const FormsyText = React.createClass({
const value = this.controlledValue(nextProps);
const isValid = this.isValidValue(value);
this.setValue(value);
this.setState({ value, isValid });
this.setState({ isValid });
}
},

Expand Down Expand Up @@ -86,12 +82,13 @@ const FormsyText = React.createClass({
if (this.isValidValue(event.target.value)) {
this.setValue(event.currentTarget.value);
// If it becomes invalid, and there isn't an error message, invalidate without error.
} else {
this.setState({ _value: event.currentTarget.value, _isPristine: false });
}
}
}

// Controlled component
this.setState({ value: event.currentTarget.value, isValid: this.isValidValue(event.currentTarget.value) });
this.setState({ isValid: this.isValidValue(event.currentTarget.value) });
if (this.props.onChange) this.props.onChange(event, event.currentTarget.value);
},

Expand Down Expand Up @@ -126,7 +123,7 @@ const FormsyText = React.createClass({
onChange={this.handleChange}
onKeyDown={this.handleKeyDown}
ref={this.setMuiComponentAndMaybeFocus}
value={this.state.value}
value={this.getValue()}
underlineStyle={this.state.isValid ? { color: this.validationColor() } : {}}
underlineFocusStyle={this.state.isValid ? { color: this.validationColor() } : {}}
/>
Expand Down

0 comments on commit 89f4e26

Please sign in to comment.