You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Anyone else having problems with an array of validations not working?
The result is always failure even when the individual validators pass.
I've tracked it down to src/lib/InputComponent.js
if(this.props.validationFunction.constructor === Array){
/*
validationFunction has to return an object in case of error,
true in case of successful validation
*/
this.props.validationFunction.map((valFn, i)=>{
let validationResult = valFn(value, this);
if(validationResult === true){
this.valid = (this.valid !== false)? validationResult : this.valid;
} else{
this.validationErrors.push(validationResult);
this.valid = false;
}
})
Looks like this.valid needs to start as true or you always get a false result and also this.props.validationFunction.map is losing 'this' context, my fix:
if(this.props.validationFunction.constructor === Array){
/*
validationFunction has to return an object in case of error,
true in case of successful validation
*/
this.valid = true;
this.props.validationFunction.map((valFn, i)=>{
let validationResult = valFn(value, this);
if(validationResult === true){
this.valid = (this.valid !== false)? validationResult : this.valid;
} else{
this.validationErrors.push(validationResult);
this.valid = false;
}
}, this)
Happy to submit a pull request :)
The text was updated successfully, but these errors were encountered:
Anyone else having problems with an array of validations not working?
The result is always failure even when the individual validators pass.
I've tracked it down to src/lib/InputComponent.js
Looks like
this.valid
needs to start as true or you always get a false result and alsothis.props.validationFunction.map
is losing 'this' context, my fix:Happy to submit a pull request :)
The text was updated successfully, but these errors were encountered: