revalidate
revalidate copied to clipboard
Possible Error in documentation for pull-request #46
Hi
Regarding this pull request https://github.com/jfairbank/revalidate/pull/46
I expect the following code to work :
export const passwordFieldValidator = composeValidators(
isRequired({
id: 'error.password.required',
description: 'Error message password required',
defaultMessage: 'You must provide a password'
}),
hasLengthGreaterThan(5)(
id: 'error.password.required',
description: 'Error message password required',
defaultMessage: 'You must provide a password'
})
)('password');
But It doesn't and I got the Error message :
Error: Please provide a string or configuration object with a `field` or `message` property
However, in order to work, I have to put a field property like this :
export const passwordFieldValidator = composeValidators(
isRequired({
field: {
id: 'error.password.required',
description: 'Error message password required',
defaultMessage: 'You must provide a password'
}
}),
hasLengthGreaterThan(5)({
field: {
id: 'error.password.required',
description: 'Error message password required',
defaultMessage: 'You must provide a password'
}
})
)('password');
If this is the case, it seems that the example in the documentation is not correct here http://revalidate.jeremyfairbank.com/usage/createValidator.html.
In the current documentation the example code is :
const requiredName = isRequired({
id: 'name',
defaultMessage: 'Name is required',
});
whereas it should be :
const requiredName = isRequired({
field : {
id: 'name',
defaultMessage: 'Name is required',
}
});
Am I correct or did I miss something ?
Best regards
You're missing you must redefine all the validators you use to support i18n. Something like this:
export const format = (msg, fields={}) => (field) => ({field, msg, ...fields});
export const isRequired = createValidator(msg => value => {
if(valueMissing(value))
return msg;
},format(messages.isRequired));
Hi, @lauterry. This is definitely an error in the documentation that I must've missed. I'll fix the docs unless you want to open a PR.
@Zagitta I'm not sure your example would work in this case unless I'm missing something.
@jfairbank It would be nice to update the docs! :)