angular-async-validator
Advanced tools
Comparing version 1.0.0 to 1.0.1
{ | ||
"name": "angular-async-validator", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Makes Angular models async validation a little less painful.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -19,3 +19,3 @@ [![Build Status](https://travis-ci.org/pocesar/angular-async-validator.svg?branch=master)](https://travis-ci.org/pocesar/angular-async-validator) [![Coverage Status](https://coveralls.io/repos/pocesar/angular-async-validator/badge.svg)](https://coveralls.io/r/pocesar/angular-async-validator) | ||
[DEMO](http://plnkr.co/edit/jIhkAPShgK4ggRYN4N1S?p=preview) | ||
[DEMO](http://embed.plnkr.co/oFVFE7/preview) | ||
@@ -46,4 +46,4 @@ ## Motivation | ||
// treat your validator like a service | ||
return function(model, options){ // receives the full blown ngModelController | ||
return SomeHttpService.check(model.$modelValue).then(function(returnedFromServer){ | ||
return function(value, options, model){ // receives the full blown ngModelController | ||
return SomeHttpService.check(model.$$rawViewValue).then(function(returnedFromServer){ | ||
if (returnedFromServer.status === 'ok') { | ||
@@ -56,5 +56,4 @@ return true; // returning boolean is fine, you can throw to break the validation | ||
}]) | ||
// by default, when the validation is truthy, the final AsyncValidator.run() call will have the ngModel.$modelValue | ||
// by default, when the validation is truthy, the final AsyncValidator.run() call will have the ngModel.$viewValue | ||
.register('required', [function(){ | ||
@@ -66,5 +65,4 @@ return function(value, options, model){ | ||
}; | ||
}]) // pluck it out from ngModel, using $$rawModelValue instead of $modelValue, because $modelValue might only be defined after required validation is actually called | ||
}], { silentRejection: false }) | ||
.register('usingValidateJs', [function(){ | ||
@@ -90,5 +88,5 @@ return function(value, options){ | ||
} | ||
return angular.equals(value.$modelValue, options.to); | ||
return angular.equals(value, options.to); | ||
}; | ||
}) | ||
}, { removeSync: true }) | ||
; | ||
@@ -228,6 +226,12 @@ | ||
Use it in your form once and apply the same validation to all underlaying models (must name your inputs or manually add them using `async-validator-add`): | ||
`async-form-validator` and `async-group-validator` can apply validations and options to the children ngModels. | ||
For `async-form-validator`, every named ngModel will be automatically added. If you want to exclude one model, add the `async-validator-exclude` to the element. You can also add non-named ngModels using `async-validator-add`. | ||
For `async-group-validator`, you can use common validators for a group of ngModels, but they don't add themselves automatically like `async-form-validator` does, you need to manually add them using `async-validator-add`. `async-group-validator` has precedence over a `async-form-validator`, so you can overwrite a group inside a form. | ||
Options are also merged from top to bottom (`async-form-validator` > `async-group-validator` > `async-validator-options` > `async-validator-options-validator`) | ||
```html | ||
<form async-validator-form="{ required: 'required', dummy: 'ctrl.controllerValidation($value)' }"> | ||
<form async-form-validator="{ required: 'required', dummy: 'ctrl.controllerValidation($value)' }"> | ||
<input | ||
@@ -246,2 +250,4 @@ type="email" | ||
<!-- apply the same validator to the models in the group --> | ||
<div async-group-validator="{ required: 'notrequired' }" async-validator-options="{ ok: true }"> | ||
@@ -263,5 +269,8 @@ <input | ||
ng-model"ctrl.data.complement" | ||
async-validator="{ myownrequired: 'bymyown' }" | ||
async-validator-exclude | ||
> | ||
<!-- async-validator-exclude will exclude the parent controller to add the validators to it --> | ||
</div> | ||
@@ -268,0 +277,0 @@ </form> |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
85703
287