Last active
May 1, 2017 02:43
-
-
Save geetotes/ca824e7753104e407be417da25e30838 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
_validate() { | |
let valid = true; | |
let { username, email } = this,state; | |
let errorMessages = { | |
username: [], | |
email: [] | |
}; | |
// Null is the default value for the username attribute, | |
// as declared in the constructor | |
if (username === null || username === '') { | |
valid = false; | |
errorMessages['username'].push('Username is required'); | |
} | |
if (email === null || email === '') { | |
valid = false; | |
errorMessages['email'].push('Email is required'); | |
} | |
// Observe how if there are no validation errors, | |
// errorMessages will have empty arrays | |
this.setState({ | |
errorMessages: errorMessages | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment