It`s a bit weird behavior, but I cannot actually figure out whats going on with my validation :)
I have a field level validation
export const confirm = (valueToConfirm, message) => (value, allValues) => {
if (value !== allValues[valueToConfirm]) {
return message;
}
return undefined;
};
And its using like
<Field
type="email"
name="confirmEmail"
component={TextInput}
validate={[required, email, confirm('email', 'Bla-bla-bla')]}
/>
And thats actually works only in case, when some another validation failed. So if user input correct all fields, and just confirmEmail would not match email - there would not be any validation error!
But if I change validation, so it would not be a function returning function - it works.
export const confirmEmail = (value, allValues) => {
if (!value || value !== allValues.email) {
return 'Bla-bla-bla';
}
return undefined;
};
P.S. Same for all Field-level validation, for example dynamic minLength
validation.
I know you are using Redux Field however this is also easily achievable with Vanilla React.