Dictionaries and Attributes
Changes:
- Rework how messages are stored within the validator, now there is a new Dictionary class involved which contains the messages generators and the attributes object.
validator.validate
orvalidator.validateAll
will now returnPromise
if at least one validation result is aPromise
.- Fix an issue when passing a configuration when installing the plugin.
Breaking Changes:
validator.updateDictionary(dictionary)
will accept a different dictionary structure than before to accommodate for theattributes
object which was mentioned here #8
Here is what the new dictionary will look like:
const dictionary = {
en: {
messages: { ... }, // Your messages to overwrite the default English messages.
attributes: { // Your custom attributes (names) for each field.
email: 'Email Address',
// ...
}
},
ar: {
messages: { ... },
attributes: { ... }
}
};
validator.updateDictionary(dictionary);
The attributes
object is not required, it is helpful if you want to display customized names in the error messages. which is surely better than using data-as
attribute on each field in your html.
However data-as
still takes precedence over the name defined in attributes
. The docs were updated with the new details.
This structure will allow flexibility with the contents of the dictionaries in the future.