Skip to content

Releases: logaretm/vee-validate

Dictionaries and Attributes

31 Aug 02:14
Compare
Choose a tag to compare

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.

Date Validations

27 Aug 16:31
Compare
Choose a tag to compare

Date validations are now available as those rules:

  • date_format:{format} validates that the field under validation must have a valid date according to the provided format.
  • after:{target} validates that the field under validation must have a valid date and is after the target input date value.
  • before:{target} validates that the field under validation must have a valid date and is before the target input date value.
  • date_between:{min,max} validates that the field under validation must have a valid date that is between the min date and the maximum date.

These validators require momentjs in order to work, you have to call validator.installDateTimeValidators(moment) and pass momentjs reference to install the validators, they are installed automatically if you have it referenced globally.

All date rules above require date_format rule to be present, since validations occur from left to right, date_format must exist before any of the other date rules. This is because it is recommended by momentjs to parse all dates with specific formats to avoid errors as much as possible. the parsing mode is always strict to further reduce parsing errors, and ultimately validation false-positives.

Strict Mode

The validators now operate by default in strict mode, which when validating non-attached fields returns false. you can turn it off using $validator.setStrictMode(false) which will turn it off for the validator instance or Validator.setStrictMode(false) to turn it off for all newly created validators.

Many thanks for:

  • @gig3m for identifying and helping fix a critical issue, also for implementing strict mode.
  • @hootlex for fixing a dead link in the docs.

Date Validations

27 Aug 16:30
Compare
Choose a tag to compare

Date validations are now available as those rules:

  • date_format:{format} validates that the field under validation must have a valid date according to the provided format.
  • after:{target} validates that the field under validation must have a valid date and is after the target input date value.
  • before:{target} validates that the field under validation must have a valid date and is before the target input date value.
  • date_between:{min,max} validates that the field under validation must have a valid date that is between the min date and the maximum date.

These validators require momentjs in order to work, you have to call validator.installDateTimeValidators(moment) and pass momentjs reference to install the validators, they are installed automatically if you have it referenced globally.

All date rules above require date_format rule to be present, since validations occur from left to right, date_format must exist before any of the other date rules. This is because it is recommended by momentjs to parse all dates with specific formats to avoid errors as much as possible. the parsing mode is always strict to further reduce parsing errors, and ultimately validation false-positives.

Strict Mode

The validators now operate by default in strict mode, which when validating non-attached fields returns false. you can turn it off using $validator.setStrictMode(false) which will turn it off for the validator instance or Validator.setStrictMode(false) to turn it off for all newly created validators.

Many thanks for:

  • @gig3m for identifying and helping fix a critical issue, also for implementing strict mode.
  • @hootlex for fixing a dead link in the docs.