Description
What problem does this feature solve?
Currently, if a custom validator fails, we get a console error log saying Invalid prop: custom validator check failed for prop 'email'
which is not helpful if you're using a third-party component. The only way to find out what failed is to jump into the source code of the component and try to understand what does this custom validator do. If the custom validator can provide a custom message that immensely changes developer experience e.g. Instead of Invalid prop: custom validator check failed for prop 'email'
, it can say, Invalid prop: the prop 'email' should be a valid GMail address.
What does the proposed API look like?
No change in API signature only behavior of validator
function. If a validator function throws an error, use it as a custom message for prop validation. Also, allow {{name}}
interpolation in error message. So the email
can be defined as:
...
props: {
email: {
validator(value) {
if (!value.endsWith('@gmail.com')) throw new Error('the prop '{{name}}' should be a valid GMail address.')
return true
}
}
...