Skip to content

Instantly share code, notes, and snippets.

this.state = {
validation:{
price: ["totalPrice"] ,
totalPrice: [greaterThanField("price")]
}
}
/* Rest of the component */
validateField = (fieldName,fieldValue) =>{
let errorMessage;
@syedsuhail
syedsuhail / validation.js
Created December 17, 2017 17:39
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 */
@syedsuhail
syedsuhail / App.js
Last active December 17, 2017 17:57
Validate field method in form component
/* Rest of the component */
validateField = (fieldName,fieldValue) =>{
let errorMessage;
this.state.validations[fieldName].forEach( (validation)=>{
errorMessage = validation(fieldValue);
if(errorMessage){return}
});
this.setState({
error:{

Business Models

Advertising

Models Examples
Display ads Yahoo!
Search ads Google