Skip to content

Instantly share code, notes, and snippets.

@geetotes
Last active May 1, 2017 02:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geetotes/ca824e7753104e407be417da25e30838 to your computer and use it in GitHub Desktop.
Save geetotes/ca824e7753104e407be417da25e30838 to your computer and use it in GitHub Desktop.
_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