Ember computed property based validations
isDirty
ember-require-module
to v0.3.0ember-validators
to 1.2.0As Ember is evolving, we have to be able to keep up. v3.x supported Ember versions as old as 1.11 which not only made this addon difficult to maintain, but also added a lot of bloat. Going forward, this addon will target and test against only the 2 latest LTS releases.
This library has always supported the ability to pass in a custom validate function
to the validator
but it didn't feel consistent with the rest of the API. To normalize
this, we created a new inline
validator that you can pass a function to via
the validate
option.
Before (3.x)
validator(function(value, options, model, attribute) {
return value === options.username ?
true :
`Username must be ${options.username}`;
}, {
username: 'offirgolan'
});
After (4.x)
validator('inline', {
username: 'offirgolan',
validate(value, options, model, attribute) {
return value === options.username ?
true :
`Username must be ${options.username}`;
}
});
Easily compose complicated validations by using this this.test
to validate
against pre-existing validators.
validate(value, options, ...args) {
let result = this.test('presence', value, { presence: true }, ...args);
if (!result.isValid) {
return result.message;
}
result = this.test('number', value, { integer: true }, ...args);
// You can easily override the error message by returning your own.
if (!result.isValid) {
return 'This value must be an integer!';
}
// Add custom logic...
return true;
}
isTruelyInvalid
property @artemgurzhii
ember-validators
to v1.0.4 @Turbo87
The isWarning
flag on the validations object as well as the individual attribute validations object has been removed since it didn't really make any sense and replace with a hasWarnings
flag.