Created
September 6, 2018 17:49
-
-
Save agoiabel/20a288eceffa3b5bae381a5b76dc4a78 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| changeHandler = event => { | |
| const name = event.target.name; | |
| const value = event.target.value; | |
| const updatedControls = { | |
| ...this.state.formControls | |
| }; | |
| const updatedFormElement = { | |
| ...updatedControls[name] | |
| }; | |
| updatedFormElement.value = value; | |
| updatedFormElement.touched = true; | |
| updatedFormElement.valid = validate(value, updatedFormElement.validationRules); | |
| updatedControls[name] = updatedFormElement; | |
| let formIsValid = true; | |
| for (let inputIdentifier in updatedControls) { | |
| formIsValid = updatedControls[inputIdentifier].valid && formIsValid; | |
| } | |
| this.setState({ | |
| formControls: updatedControls, | |
| formIsValid: formIsValid | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment