Skip to content

Instantly share code, notes, and snippets.

@syedsuhail
Created December 17, 2017 17:39
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 syedsuhail/f022da37a923d5dbc7767de9196821b9 to your computer and use it in GitHub Desktop.
Save syedsuhail/f022da37a923d5dbc7767de9196821b9 to your computer and use it in GitHub Desktop.
Validation based on value of another field
const greaterThanField = (fieldName) => (fieldValue,formData) =>
fieldValue > formData[fieldName] ? undefined : `Value must be greater that ${fieldName}`;
/* Rest of the component */
this.state = {
validation:{
totalPrice: [greaterThanField("price")]
}
}
/* Rest of the component */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment