Closed joneyphair closed 7 years ago
thx
Is there a way to set a generic message for all error types on a field or do you need to override each type i.e. show Invalid Password for all these (required|string|between).
I think you can achieve that using .invalidate('a generic error message')
on Fields instances when they don't pass validation (for example observing Field's isValid prop). The invalidate method will overwrite the last error message.
For the DVR case, it seems to be impossible to set custom message messages for the conditional rules (require_if) because a) it doesn't appear to be possible to make conditional rules with the register rule method and b) custom messages are passed into the constructor, which we don't have access to.
If you use DVR Validator , to automatically change the language for all errors, you can simply do it like this:
import validatorjs from 'validatorjs';
import MobxReactForm from 'mobx-react-form';
import { observer } from 'mobx-react';
// For french For example:
validatorjs.useLang('fr');
Related to #305
Hi @joneyphair, it depends on which plugin you are using.
Using Vanilla Javascript Validation Functions (VJF) you can provide it into the function. The function have to return a boolean or an array with [boolean, string], which the second argument is the error message for the custom functions.
Using Json Schema Validation Keywords (SVK) with ajv you can provide error messages for custom keywords, or override existing custom messages.
Using Declarative Validation Rules (DVR) you can provide custom error messages for custom registered rules, or you can override the default messages when extending the plugin:
I will improve the documentation about custom error messages in the future.