-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
251 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# v3.4.0 | ||
|
||
add lt and gt validator | ||
|
||
# v3.5.0 | ||
|
||
re-trigger validate when validate-property change |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Directive, Input, forwardRef, OnInit, OnChanges, SimpleChanges } from '@angular/core'; | ||
import { NG_VALIDATORS, Validator, ValidatorFn, AbstractControl } from '@angular/forms'; | ||
|
||
import { CustomValidators } from '../index'; | ||
|
||
const GREATER_THAN_VALIDATOR: any = { | ||
provide: NG_VALIDATORS, | ||
useExisting: forwardRef(() => GreaterThanValidator), | ||
multi: true | ||
}; | ||
|
||
@Directive({ | ||
selector: '[gt][formControlName],[gt][formControl],[gt][ngModel]', | ||
providers: [GREATER_THAN_VALIDATOR] | ||
}) | ||
export class GreaterThanValidator implements Validator, OnInit, OnChanges { | ||
@Input() gt: number; | ||
|
||
private validator: ValidatorFn; | ||
private onChange: () => void; | ||
|
||
ngOnInit() { | ||
this.validator = CustomValidators.gt(this.gt); | ||
} | ||
|
||
ngOnChanges(changes: SimpleChanges) { | ||
for (let key in changes) { | ||
if (key === 'gt') { | ||
this.validator = CustomValidators.gt(changes[key].currentValue); | ||
if (this.onChange) this.onChange(); | ||
} | ||
} | ||
} | ||
|
||
validate(c: AbstractControl): {[key: string]: any} { | ||
return this.validator(c); | ||
} | ||
|
||
registerOnValidatorChange(fn: () => void): void { | ||
this.onChange = fn; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Directive, Input, forwardRef, OnInit, OnChanges, SimpleChanges } from '@angular/core'; | ||
import { NG_VALIDATORS, Validator, ValidatorFn, AbstractControl } from '@angular/forms'; | ||
|
||
import { CustomValidators } from '../index'; | ||
|
||
const LESS_THAN_VALIDATOR: any = { | ||
provide: NG_VALIDATORS, | ||
useExisting: forwardRef(() => LessThanValidator), | ||
multi: true | ||
}; | ||
|
||
@Directive({ | ||
selector: '[lt][formControlName],[lt][formControl],[lt][ngModel]', | ||
providers: [LESS_THAN_VALIDATOR] | ||
}) | ||
export class LessThanValidator implements Validator, OnInit, OnChanges { | ||
@Input() lt: number; | ||
|
||
private validator: ValidatorFn; | ||
private onChange: () => void; | ||
|
||
ngOnInit() { | ||
this.validator = CustomValidators.lt(this.lt); | ||
} | ||
|
||
ngOnChanges(changes: SimpleChanges) { | ||
for (let key in changes) { | ||
if (key === 'lt') { | ||
this.validator = CustomValidators.lt(changes[key].currentValue); | ||
if (this.onChange) this.onChange(); | ||
} | ||
} | ||
} | ||
|
||
validate(c: AbstractControl): {[key: string]: any} { | ||
return this.validator(c); | ||
} | ||
|
||
registerOnValidatorChange(fn: () => void): void { | ||
this.onChange = fn; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.