ng2-validation
Advanced tools
Comparing version 3.1.4 to 3.2.4
@@ -97,2 +97,6 @@ import { ValidatorFn, AbstractControl } from '@angular/forms'; | ||
static equalTo(equalControl: AbstractControl): ValidatorFn; | ||
/** | ||
* Validator that requires controls to have a value to not equal another control. | ||
*/ | ||
static notEqualTo(notEqualControl: AbstractControl): ValidatorFn; | ||
} |
@@ -279,2 +279,18 @@ "use strict"; | ||
}; | ||
/** | ||
* Validator that requires controls to have a value to not equal another control. | ||
*/ | ||
CustomValidators.notEqualTo = function (notEqualControl) { | ||
var subscribe = false; | ||
return function (control) { | ||
if (!subscribe) { | ||
subscribe = true; | ||
notEqualControl.valueChanges.subscribe(function () { | ||
control.updateValueAndValidity(); | ||
}); | ||
} | ||
var v = control.value; | ||
return notEqualControl.value !== v ? null : { notEqualTo: true }; | ||
}; | ||
}; | ||
return CustomValidators; | ||
@@ -281,0 +297,0 @@ }()); |
@@ -22,2 +22,3 @@ "use strict"; | ||
var equal_to_1 = require('./directives/equal-to'); | ||
var not_equal_to_1 = require('./directives/not-equal-to'); | ||
exports.CUSTOM_FORM_DIRECTIVES = [ | ||
@@ -42,3 +43,4 @@ range_length_1.RangeLengthValidator, | ||
equal_1.EqualValidator, | ||
equal_to_1.EqualToValidator | ||
equal_to_1.EqualToValidator, | ||
not_equal_to_1.NotEqualToValidator, | ||
]; | ||
@@ -45,0 +47,0 @@ var CustomFormsModule = (function () { |
@@ -1,1 +0,1 @@ | ||
{"__symbolic":"module","version":1,"metadata":{"CUSTOM_FORM_DIRECTIVES":[{"__symbolic":"reference","module":"./directives/range-length","name":"RangeLengthValidator"},{"__symbolic":"reference","module":"./directives/min","name":"MinValidator"},{"__symbolic":"reference","module":"./directives/max","name":"MaxValidator"},{"__symbolic":"reference","module":"./directives/range","name":"RangeValidator"},{"__symbolic":"reference","module":"./directives/digits","name":"DigitsValidator"},{"__symbolic":"reference","module":"./directives/number","name":"NumberValidator"},{"__symbolic":"reference","module":"./directives/url","name":"UrlValidator"},{"__symbolic":"reference","module":"./directives/email","name":"EmailValidator"},{"__symbolic":"reference","module":"./directives/date","name":"DateValidator"},{"__symbolic":"reference","module":"./directives/min-date","name":"MinDateValidator"},{"__symbolic":"reference","module":"./directives/max-date","name":"MaxDateValidator"},{"__symbolic":"reference","module":"./directives/date-iso","name":"DateISOValidator"},{"__symbolic":"reference","module":"./directives/credit-card","name":"CreditCardValidator"},{"__symbolic":"reference","module":"./directives/json","name":"JSONValidator"},{"__symbolic":"reference","module":"./directives/base64","name":"Base64Validator"},{"__symbolic":"reference","module":"./directives/phone","name":"PhoneValidator"},{"__symbolic":"reference","module":"./directives/uuid","name":"UUIDValidator"},{"__symbolic":"reference","module":"./directives/equal","name":"EqualValidator"},{"__symbolic":"reference","module":"./directives/equal-to","name":"EqualToValidator"}],"CustomFormsModule":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"NgModule"},"arguments":[{"declarations":[{"__symbolic":"reference","name":"CUSTOM_FORM_DIRECTIVES"}],"exports":[{"__symbolic":"reference","name":"CUSTOM_FORM_DIRECTIVES"}]}]}]}}} | ||
{"__symbolic":"module","version":1,"metadata":{"CUSTOM_FORM_DIRECTIVES":[{"__symbolic":"reference","module":"./directives/range-length","name":"RangeLengthValidator"},{"__symbolic":"reference","module":"./directives/min","name":"MinValidator"},{"__symbolic":"reference","module":"./directives/max","name":"MaxValidator"},{"__symbolic":"reference","module":"./directives/range","name":"RangeValidator"},{"__symbolic":"reference","module":"./directives/digits","name":"DigitsValidator"},{"__symbolic":"reference","module":"./directives/number","name":"NumberValidator"},{"__symbolic":"reference","module":"./directives/url","name":"UrlValidator"},{"__symbolic":"reference","module":"./directives/email","name":"EmailValidator"},{"__symbolic":"reference","module":"./directives/date","name":"DateValidator"},{"__symbolic":"reference","module":"./directives/min-date","name":"MinDateValidator"},{"__symbolic":"reference","module":"./directives/max-date","name":"MaxDateValidator"},{"__symbolic":"reference","module":"./directives/date-iso","name":"DateISOValidator"},{"__symbolic":"reference","module":"./directives/credit-card","name":"CreditCardValidator"},{"__symbolic":"reference","module":"./directives/json","name":"JSONValidator"},{"__symbolic":"reference","module":"./directives/base64","name":"Base64Validator"},{"__symbolic":"reference","module":"./directives/phone","name":"PhoneValidator"},{"__symbolic":"reference","module":"./directives/uuid","name":"UUIDValidator"},{"__symbolic":"reference","module":"./directives/equal","name":"EqualValidator"},{"__symbolic":"reference","module":"./directives/equal-to","name":"EqualToValidator"},{"__symbolic":"reference","module":"./directives/not-equal-to","name":"NotEqualToValidator"}],"CustomFormsModule":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"NgModule"},"arguments":[{"declarations":[{"__symbolic":"reference","name":"CUSTOM_FORM_DIRECTIVES"}],"exports":[{"__symbolic":"reference","name":"CUSTOM_FORM_DIRECTIVES"}]}]}]}}} |
{ | ||
"name": "ng2-validation", | ||
"version": "3.1.4", | ||
"version": "3.2.4", | ||
"description": "angular2 validation", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -41,2 +41,3 @@ # Description | ||
- equalTo | ||
- notEqualTo | ||
@@ -236,2 +237,11 @@ # Usage | ||
### notEqualTo | ||
```html | ||
<input type="text" ngModel name="password" #password="ngModel" required/> | ||
<p *ngIf="password.errors?.required">required error</p> | ||
<input type="password" ngModel name="certainPassword" #certainPassword="ngModel" [notEqualTo]="password"/> | ||
<p *ngIf="certainPassword.errors?.equalTo">equalTo error</p> | ||
``` | ||
## model driven | ||
@@ -413,4 +423,25 @@ | ||
### notEqualTo | ||
```javascript | ||
let password = new FormControl('', Validators.required); | ||
let certainPassword = new FormControl('', CustomValidators.notEqualTo(password)); | ||
this.form = new FormGroup({ | ||
password: password, | ||
certainPassword: certainPassword | ||
}); | ||
``` | ||
```html | ||
<form [formGroup]="form"> | ||
<input type="password" formControlName="password"/> | ||
<p *ngIf="form.controls.password.errors?.required">required error</p> | ||
<input type="password" formControlName="certainPassword"/> | ||
<p *ngIf="form.controls.certainPassword.errors?.notEqualTo">notEqualTo error</p> | ||
</form> | ||
``` | ||
# License | ||
MIT |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
103577
100
1302
445