Validations
addon/validations/result.js:24
Running Manual Validations
Although validations are lazily computed, there are times where we might want to force all or specific validations to happen. For this reason we have exposed two methods:
- validateSync: Should only be used if all validations are synchronous. It will throw an error if any of the validations are asynchronous
- validate: Will always return a promise and should be used if asynchronous validations are present
Inspecting Validations
All validations can be accessed via the validations
object created on your model/object.
Each attribute also has its own validation which has the same properties.
An attribute validation can be accessed via validations.attrs.<ATTRIBUTE>
which will return a ResultCollection.
Global Validations
Global validations exist on the validations
object that resides on the object that is being validated.
To see all possible properties, please checkout the docs for ResultCollection.
model.get('validations.isValid');
model.get('validations.errors');
model.get('validations.messages');
// etc...
Attribute Validations
The validations
object also contains an attrs
object which holds a ResultCollection
for each attribute specified in your validation rules.
model.get('validations.attrs.username.isValid');
model.get('validations.attrs.password.errors');
model.get('validations.attrs.email.messages');
// etc...