Skip to content

Releases: adopted-ember-addons/ember-cp-validations

v2.7.1

13 Apr 17:47
Compare
Choose a tag to compare
  • #159 Fix deprecation warning Ember.merge > Ember.assign for Ember >= 2.5.0 @urbany

Time to Go Global

08 Apr 18:40
Compare
Choose a tag to compare

If you have specific options you want to propagate throughout all your validation rules, you can do so by passing in a global options object. This is ideal for when you have a dependent key that each validator requires such as the current locale from your i18n implementation, or you want easily toggle your validations on/off.

const Validations = buildValidations(validationRules, globalOptions);
import Ember from 'ember';
import { validator, buildValidations } from 'ember-cp-validations';
const Validations = buildValidations({
  firstName: {
    description: 'First Name'
    validators: [
      validator('presence', {
        presence: true,
        dependentKeys: ['foo', 'bar']
      })
     ]
   },
  lastName: validator('presence', true)
}, {
  description: 'This field'
  dependentKeys: ['i18n.locale', 'disableValidations'],
  disabled() {
    return this.get('model.disableValidations');
  }
});

Just like in the default options, local validator options will always take precedence over default options and default options will always take precedence over global options. This allows you to declare global rules while having the ability to override them in lower levels. This rule does not apply to dependentKeys, instead they all are merged. In the example above, firstName's dependentKeys will be ['i18n.locale', 'disableValidations', 'foo', 'bar']

Upgrade Notes

If you have a custom validator and are using the buildOptions hook, please add globalOptions to your parameters to be able to use this feature.

buildOptions(options = {}, defaultOptions = {}})

To:

buildOptions(options = {}, defaultOptions = {}, globalOptions = {})

v2.6.1

16 Mar 17:42
Compare
Choose a tag to compare

Nested Keys

09 Mar 20:10
Compare
Choose a tag to compare
  • #132 Add support for nested keys in validation rules.
  • #132 Create validations object once per class instead of every instance

When declaring object validations (not including Ember Data models), it is possible to validate child objects from the parent object.

import Ember from 'ember';
import { validator, buildValidations } from 'ember-cp-validations';

const Validations = buildValidations({
  'acceptTerms': validator('inclusion', { in: [ true ] }),
  'user.firstName': validator('presence', true),
  'user.lasName': validator('presence', true),
  'user.account.number': validator('number')
});

export default Ember.Component.extend(Validations, {
  acceptTerms: false,
  user:  { 
    firstName: 'John', 
    lastName: 'Doe' ,
    account: { 
      number: 123456, 
    }
  },
  isFormValid: Ember.computed.alias('validations.isValid'),
});

DS Error Validator

23 Feb 22:44
Compare
Choose a tag to compare
  • #122 Blueprints/validator-test: Fix typo in _filesPath() method @Turbo87
  • #127 DS Error validator. See docs here

v2.4.1

19 Feb 07:30
Compare
Choose a tag to compare
  • #119 Fix for Dependent keys containing @each only work one level deep warnings in Ember Canary - 2.5
  • #124 Validate on runs validation on all attributes @kat3kasper

Inheritance & Relations

12 Feb 19:15
Compare
Choose a tag to compare
  • #112 Support validations via inheritance
  • #116 Support relational validators (has-many and belongs-to) in plain Ember Objects
  • #117 Move caches out of the prototype and into the instance

Disable validations

09 Feb 20:49
Compare
Choose a tag to compare
  • #106 Ability to enable/disable validations. See documentation here

Debounced Validations

09 Feb 20:50
Compare
Choose a tag to compare
  • #92 Debounced Validation
  • #96 Expose options property for attribute validations which contains a hash of built options grouped by validator type

v2.0.0

09 Feb 20:52
Compare
Choose a tag to compare
  • Renamed attributeDescription to description
  • I18n support (currently Ember-Intl & Ember-I18n)
  • Added hooks in both Message base and validator base
  • Validation options can also be function that are called before validate
  • #27 Declare custom dependent keys in validators (both custom and predefined)
  • #30 MomentJS is now only required if you want to use the date validator and is no longer a forced dependency
  • #33 Removed Ember.String.fmt dependency
  • #38 Default options in validation declarations

Upgrade Notes

Please checkout the upgrading documentation for more details.