Methods
- buildValidations
- createAttrsClass
- createCPValidationFor
- createTopLevelPropsMixin
- createValidationsClass
- createValidatorsFor
- extractOptionsDependentKeys
- generateValidationResultsFor
- getCPDependentKeysFor
- getValidatorCacheFor
- getValidatorsFor
- hasOption
- normalizeOptions
- resolveDebounce
- validate
- validateAttribute
- validateSync
- validationReturnValueHandler
-
validations
Top level method that will ultimately return a mixin with all CP validations
Parameters:
-
validations
ObjectValidation rules
Returns:
-
validatableAttributes
-
validationRules
-
model
Creates the attrs
class which holds all the CP logic
model.get('validations.attrs.username');
model.get('validations.attrs.nested.object.attribute');
Returns:
-
attribute
-
model
-
validations
CP generator for the given attribute
Parameters:
Returns:
A computed property which is a ResultCollection
-
validations
Create a mixin that will have all the top level CPs under the validations object. These are computed collections on different properties of each attribute validations CP
Parameters:
-
validations
Object
-
inheritedValidationsClass
-
validations
-
model
Creates the validations class that will become model.validations
.
- Setup parent validation inheritance
- Normalize nested keys (i.e. 'details.dob') into objects (i.e { details: { dob: validator() }})
- Merge normalized validations with parent
- Create global CPs (i.e. 'isValid', 'messages', etc...)
Returns:
-
attribute
-
model
Create validators for the give attribute and store them in a cache
Returns:
-
options
Extract all dependentKeys from any property that is a CP
Parameters:
-
options
Object
Returns:
dependentKeys
-
attribute
-
model
-
validators
-
validate
-
opts
Generates the validation results for a given attribute and validators. If a given validator should be validated, it calls upon the validate callback to retrieve the result.
Parameters:
Returns:
-
attribute
-
model
-
validations
CP dependency generator for a give attribute depending on its relationships
Parameters:
Returns:
Unique list of dependencies
-
attribute
-
model
Get debounced validation cache for the given attribute. If it doesn't exist, create a new one.
Returns:
-
attribute
-
model
Get validators for the give attribute. If they are not in the cache, then create them.
Returns:
-
validations
-
option
-
value=true
Check if a collection of validations have an option equal to the given value
Returns:
-
validations
Validation rules can be created with default and global options { description: 'Username', validators: [...] }
This method generate the default options pojo, applies it to each validation rule, and flattens the object
Parameters:
-
validations
Object
Returns:
-
resolve
Call the passed resolve method. This is needed as debounced expects a static method to work properly.
Parameters:
-
resolve
Function
-
options
-
isAsync
model.validate({ on: ['username', 'email'] }).then(({ m, validations }) => {
validations.get('isValid'); // true or false
validations.get('isValidating'); // false
let usernameValidations = m.get('validations.attrs.username');
usernameValidations.get('isValid') // true or false
});
Parameters:
Returns:
Promise if isAsync is true, object if isAsync is false
-
attribute
-
value
A functional approach to check if a given attribute on a model is valid independently of the model attribute's validations. This method will always return a promise which will then resolve to a ResultCollection.
model.validateAttribute('username', 'offirgolan').then(({ m, validations }) => {
validations.get('isValid'); // true or false
validations.get('isValidating'); // false
});
Parameters:
-
attribute
String -
value
Mixed
Returns:
-
options
let { m, validations } = model.validateSync();
validations.get('isValid') // true or false