Perform Validation When Button Is Clicked In Reactjs
Solution 1:
So there are a few things that has to be fixed here in order to make it work. But we will have it done in no time
#1 The for each error
First of all you are calling the forEach on the object (newUser) before you have initialized it. Not having defined a variable leads to it being... undefined. Ergo the error
Cannot read property 'forEach' of undefined thanks in advance
However, even if we were to fix that and swapped the place of the 2, it still would not work. You are calling the function forEach that is a property of the array object in javascript when in fact your newUser is a js object. In order for you to loop over the keys in your object you are going to want to default to a normal for loop looking like this
for(var key in newUser){
isValid = this.validateField(key) && isValid;
}
Hopefully this fixes your problem
Post a Comment for "Perform Validation When Button Is Clicked In Reactjs"