Skip to content

Commit

Permalink
Merge pull request #192 from rojobuffalo/dev
Browse files Browse the repository at this point in the history
Revert #174 and re-apply interim changes
  • Loading branch information
Ryan Blakeley authored Feb 9, 2017
2 parents 6f96cce + 9dbf041 commit aca33b4
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/FormsyText.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ const FormsyText = React.createClass({
underlineStyle: {},
},

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

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

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

Expand Down Expand Up @@ -88,13 +93,12 @@ 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 });
}
}
}

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

Expand All @@ -116,8 +120,7 @@ const FormsyText = React.createClass({
validationError, // eslint-disable-line no-unused-vars
validationErrors, // eslint-disable-line no-unused-vars
value, // eslint-disable-line no-unused-vars
...rest,
} = this.props;
...rest } = this.props;

const { isRequired, isPristine, isValid, isFormSubmitted } = this;
const isRequiredError = isRequired() && !isPristine() && !isValid() && isFormSubmitted() && requiredError;
Expand All @@ -132,7 +135,7 @@ const FormsyText = React.createClass({
onChange={this.handleChange}
onKeyDown={this.handleKeyDown}
ref={this.setMuiComponentAndMaybeFocus}
value={this.getValue()}
value={this.state.value}
underlineStyle={this.state.isValid ? { color: this.validationColor() } : underlineStyle}
underlineFocusStyle={this.state.isValid ? { color: this.validationColor() } : underlineFocusStyle}
/>
Expand Down

0 comments on commit aca33b4

Please sign in to comment.