FormConstraint
Specifies what constraints a given form field must satisfy
Static Method Summary
Static Public Methods | ||
public static |
observeValidation(validationObservers: ...Observable<ValidationError[]>): Observable<boolean> Takes list of observers over which to observe validation. |
Constructor Summary
Public Constructor | ||
public |
Creates a form constraint (doing nothing). |
Method Summary
Public Methods | ||
public |
addValidator(callback: Function, error: string, opts: Object) Adds a validator to execute |
|
public |
flatten(constraint: FormConstraint): FormConstraint Flatten a validator into a single one |
|
public |
hasValue(error: string): FormConstraint Checks if has a value |
|
public |
Checks if a field is an email |
|
public |
Allows the value to either follow validations or be empty. |
|
public |
length(min: number, max: number): FormConstraint Specifies the length must be between (inclusive) bounds between a min and a max. |
|
public |
notEmpty(error: string): FormConstraint Makes sure a form value is not empty |
|
public |
or(caseA: FormConstraint, caseB: FormConstraint): FormConstraint Adds an OR validator. |
|
public |
regex(regex: RegExp): FormConstraint Requires a field to match a certain regex. |
|
public |
validate(value: any): ValidationError[] Runs validation on the element. |
Static Public Methods
public static observeValidation(validationObservers: ...Observable<ValidationError[]>): Observable<boolean> source
Takes list of observers over which to observe validation.
Params:
Name | Type | Attribute | Description |
validationObservers | ...Observable<ValidationError[]> |
Public Constructors
Public Methods
public addValidator(callback: Function, error: string, opts: Object) source
Adds a validator to execute
public flatten(constraint: FormConstraint): FormConstraint source
Flatten a validator into a single one
Params:
Name | Type | Attribute | Description |
constraint | FormConstraint |
public hasValue(error: string): FormConstraint source
Checks if has a value
Params:
Name | Type | Attribute | Description |
error | string | Error to show |
public isEmpty(): FormConstraint source
Allows the value to either follow validations or be empty. Empty is defined as null or having no length.
public length(min: number, max: number): FormConstraint source
Specifies the length must be between (inclusive) bounds between a min and a max. For input elements.
public notEmpty(error: string): FormConstraint source
Makes sure a form value is not empty
Params:
Name | Type | Attribute | Description |
error | string | error string to show. |
public or(caseA: FormConstraint, caseB: FormConstraint): FormConstraint source
Adds an OR validator.
Params:
Name | Type | Attribute | Description |
caseA | FormConstraint | The first case |
|
caseB | FormConstraint | The second case |
public regex(regex: RegExp): FormConstraint source
Requires a field to match a certain regex.
Params:
Name | Type | Attribute | Description |
regex | RegExp | Regex to match |
public validate(value: any): ValidationError[] source
Runs validation on the element.
Params:
Name | Type | Attribute | Description |
value | any | Any value to run validator on |