Skip to content

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

v3.1.2

07 Nov 08:39
Compare
Choose a tag to compare
  • #389 [BUGFIX] Resolve _type conflicts with EmberValidator classes

v3.1.1

03 Nov 22:52
Compare
Choose a tag to compare
  • #383 [BUGFIX] Use ember-require-module

v3.1.0

04 Oct 22:24
Compare
Choose a tag to compare
  • #363 Use ember-validators
  • #364 [FEATURE] Volatile option

v2.9.7

21 Sep 09:41
Compare
Choose a tag to compare

v3.0.1

14 Sep 18:04
Compare
Choose a tag to compare
  • #344 [BUGFIX] DEPRECATION: Ember.Handlebars.SafeString @kepek

v3.0.0

12 Sep 16:34
Compare
Choose a tag to compare

Upgrade Notes

Computed Options

In 2.x, we introduced the notion of Options as Functions which allowed any validator's option to be a function that would be lazily called right before a validation happened. In 3.x, we noticed that such implementation very much resembled the workings of a Computed Property (without the caching of course). Converting our functional approach to an Ember CP approach made defining validations a whole lot simpler.

Before (2.x)

validator('length', {
  dependentKeys: ['isEnabled', 'meta.username.minLength', 'meta.username.maxLength'],
  disabled(model) {
    return !model.get('isEnabled');
  },
  min(model) {
    return model.get('meta.username.minLength')
  },
  max(model) {
    return model.get('meta.username.maxLength')
  },
  description(model, attribute) {
    return model.generateDescription(attribute);
  }
});

After (3.x)

validator('length', {
  disabled: Ember.computed.not('model.meta.username.isEnabled'),
  min: Ember.computed.readOnly('model.meta.username.minLength'),
  max: Ember.computed.readOnly('model.meta.username.maxLength'),
  description: Ember.computed(function() {
    // CPs have access to the `model` and `attribute`
    return this.get('model').generateDescription(this.get('attribute'));
  }).volatile() // Disable caching and force recompute on every get call
});

Some more reasons why this is better:

  • Any option that uses a CP doesn't have to re-declare those dependents in the dependentKeys collection.
  • You can use any Ember.computed operation (computed.and, computed.or, computed.filterBy, etc.)

dependentKeys

There might be instances where your validator is dependent on external properties. For this reason, we introduced dependentKeys in 2.x. In 3.x, the only change to this is that all dependent keys must be prefixed with model.

Before (2.x)

validator('presence', {
  presence: true,
  dependentKeys: ['someService.someProperty', 'foo', 'bar.baz']
});

After (3.x)

validator('presence', {
  presence: true,
  dependentKeys: ['model.someService.someProperty', 'model.foo', 'model.bar.baz']
});

New Features

Warning Validators

Any validator can be declared as a warning validator by setting isWarning to true. These validators will act as assertions that when return a message, will be placed under warnings and warningMessages collections. What this means, is that these validators will not have any affect on the valid state of the attribute allowing you to display warning messages even when the attribute is valid.

password: {
  description: 'Password',
  validators: [
    validator('length', {
      min: 4,
      max: 10
    }),
    validator('length', {
      isWarning: true,
      min: 6,
      message: 'What kind of weak password is that?'
    })
  ]
}

screen shot 2016-06-23 at 4 19 10 pm

Lazy Validators

By default, all validators are set to be lazily executed, meaning they will only be run if required. To turn this off, just set the lazy option on your validator to false

Pull Requests

  • #226 Warning Validators
  • #232 Computed Options (special thanks to @xcambar)
  • #239 Use Require for Checking Ember Data
  • #240 DS Error Validator + Nested Keys
  • #241 Fix blueprint warning
  • #245 Utilize root in validator blueprint
  • #249 Fixed email regex of format validator @simonihmig
  • #252 Fix require module
  • #262 Use model instead of _model when declaring custom dependents
  • #266 Check for null in extractOptionsDependentKeys @xcambar
  • #272 Fix ember-cli deprecation warning
  • #294 [BUGFIX] Validate promise resolves even when validations are still validating
  • #305 [BUGFIX] Provide baseDir to allow for proper caching
  • #311 [FEATURE] Place mixin under a named scope for Ember Inspector
  • #312 [BUGFIX] Deleted DS.Model records should be suppressed
  • #321 [FEATURE] Lazily run validations
  • #330 [FEATURE] Add option allowNonTld for email format validator @indr
  • #333 [BUGFIX] Define CPs and nested CPs in attrs object once per class
  • #338 [FEATURE] Add validator type to error messages @kepek
  • #339 [BUGFIX] Allow for requirejs.has to not be available @jasonmit

Thank you to all who took the time to contribute!

v2.9.6

12 Sep 16:19
Compare
Choose a tag to compare
  • #339 [BUGFIX] Allow for requirejs.has to not be available @jasonmit

v3.0.0-beta.7

07 Sep 19:00
Compare
Choose a tag to compare
v3.0.0-beta.7 Pre-release
Pre-release
  • #330 [FEATURE] Add option allowNonTld for email format validator @indr
  • #333 [BUGFIX] Define CPs and nested CPs in attrs object once per class

Lets get lazy

19 Aug 21:51
Compare
Choose a tag to compare
Lets get lazy Pre-release
Pre-release
  • #305 [BUGFIX] Provide baseDir to allow for proper caching
  • #311 [FEATURE] Place mixin under a named scope for Ember Inspector
  • #312 [BUGFIX] Deleted DS.Model records should be suppressed
  • #321 [FEATURE] Lazily run validations

v2.9.5

18 Aug 18:33
Compare
Choose a tag to compare
Release v2.9.5.