Releases: adopted-ember-addons/ember-cp-validations
v2.7.1
Time to Go Global
- #146 Global options
- #152 Export validators from addon namespace @luxferresum
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
- #140 Fixed moment date parsing deprecations @danielspaniel
Nested Keys
- #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
v2.4.1
- #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
Disable validations
Debounced Validations
v2.0.0
- Renamed
attributeDescription
todescription
- 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.