updateFieldResults
Usage
const personValidator = form({
firstName: [
required(),
length({minLength: 2, maxLength: 20})
],
lastName: [
required(),
length({minLength: 2, maxLength: 20})
],
birthYear: range({min: 1900, max: 2018})
});
let stanfordStrickland = {
firstName: 'Stanford',
lastName: 'Strickland',
birthYear: 1925
};
let stanfordResult = validate(personValidator, stanfordStrickland);
let firstNameResult = {
isValid: false,
value: 'Stanford',
message: 'The service does not allow a first name of "Stanford"'
};
stanfordResult = personValidator.updateFieldResults(
stanfordResult,
{firstName: firstNameResult}
);
/*
stanfordResult = {
form: {
validationResults: {
firstName: {
isValid: false,
value: 'Stanford',
message: 'The service does not allow a first name of "Stanford"'
},
lastName: {
isValid: true
},
birthYear: {
isValid: true
}
},
validationErrors: [
{
fieldName: 'firstName',
isValid: false,
value: 'Stanford',
message: 'The service does not allow a first name of "Stanford"'
}
],
isComplete: true
}
}
*/Removing Results
Last updated