Skip to content

Dictionaries and Attributes

Compare
Choose a tag to compare
@logaretm logaretm released this 31 Aug 02:14
· 4589 commits to main since this release

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 or validator.validateAll will now return Promise if at least one validation result is a Promise.
  • 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 the attributes 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.