src/lib/components/custom-validator/custom-validator.component.ts
Angular Component for the CustomValidator Control.
providers |
{ provide: BaseValidatorService, useExisting: WebFormsBaseValidatorService }
|
selector | wm-custom-validator |
styleUrls | ./custom-validator.component.scss |
templateUrl | ./custom-validator.component.html |
Properties |
|
Methods |
Inputs |
constructor(wmService: WebMapService, refChange: ChangeDetectorRef, render2: Renderer2, elem: ElementRef, webComponents: WebComponentsService, validatorService: BaseValidatorService, bringTopServ1: BringTopService)
|
||||||||||||||||||||||||
Creates an instance of CustomValidatorComponent.
Parameters :
|
clientValidationFunction | |
Type : (expression: string) => boolean
|
|
Default value : (expression: string): boolean => {
return true;
}
|
|
Arrow function to evaluate the expression of the attached component. |
controlToValidate | |
Type : string
|
|
Inherited from
BaseValidatorComponent
|
|
Defined in
BaseValidatorComponent:130
|
|
Gets/sets the Control to Validate and notify the service. |
errorMessage | |
Type : string
|
|
Inherited from
BaseValidatorComponent
|
|
Defined in
BaseValidatorComponent:146
|
|
Gets/sets the error message. |
validateControl |
validateControl(controlToValidateId: string, expression: string)
|
Inherited from
BaseValidatorComponent
|
Defined in
BaseValidatorComponent:105
|
Executes the clientValidationFunction to validate the component attached.
Returns :
boolean
{boolean} |
displayMessage |
displayMessage()
|
Inherited from
BaseValidatorComponent
|
Defined in
BaseValidatorComponent:224
|
If the text property is defined, it has to be shown instead of the error message
Returns :
string
The property to display |
ngOnDestroy |
ngOnDestroy()
|
Inherited from
BaseValidatorComponent
|
Defined in
BaseValidatorComponent:120
|
OnDestroy lifecycle hook, removes itself from the service.
Returns :
void
|
ngOnInit |
ngOnInit()
|
Inherited from
BaseValidatorComponent
|
Defined in
BaseValidatorComponent:111
|
OnInit lifecycle hook, adds itself to the service.
Returns :
void
|
Protected controlToValidateInternal |
Type : string
|
Default value : ''
|
Inherited from
BaseValidatorComponent
|
Defined in
BaseValidatorComponent:71
|
Property with the Id of the control to validate. |
Private displayInternal |
Default value : ValidatorDisplay.Static
|
Inherited from
BaseValidatorComponent
|
Defined in
BaseValidatorComponent:93
|
Internal property for handle type of Display in component |
Protected errorMessageInternal |
Type : string
|
Default value : ''
|
Inherited from
BaseValidatorComponent
|
Defined in
BaseValidatorComponent:78
|
Property with the error message. |
Protected hiddenInternal |
Default value : true
|
Inherited from
BaseValidatorComponent
|
Defined in
BaseValidatorComponent:64
|
Property with the visibility of the component. |
Protected validationGroupInternal |
Type : string
|
Default value : ''
|
Inherited from
BaseValidatorComponent
|
Defined in
BaseValidatorComponent:85
|
Property with the validationGroup @memberof BaseValidatorComponent |
Protected validationSuccessInternal |
Default value : false
|
Inherited from
BaseValidatorComponent
|
Defined in
BaseValidatorComponent:57
|
Property with that indicates if the validation is passed. |
import {
Optional,
ChangeDetectorRef,
Component,
Input,
ElementRef,
Renderer2
} from '@angular/core';
import { dataTransfer, BringTopService } from '@mobilize/base-components';
import { BaseValidatorComponent } from '../base-validator/BaseValidator';
import { ErrorCodes, ExceptionHandlerClass } from '@mobilize/webmap-core';
import { WebMapService } from '@mobilize/angularclient';
import { WebFormsBaseValidatorService } from '../../services/base-validator-service/web-forms-base-validator.service';
import { ValidatorDisplay } from '../../contracts/ValidatorDisplay';
import {
BaseValidatorService,
WebComponentsService
} from '@mobilize/winforms-components';
/**
* Angular Component for the CustomValidator Control.
*
* @export
* @class CustomValidatorComponent
* @extends {BaseValidatorComponent}
*/
@Component({
selector: 'wm-custom-validator',
templateUrl: './custom-validator.component.html',
styleUrls: ['./custom-validator.component.scss'],
inputs: ['model'],
providers: [
{ provide: BaseValidatorService, useExisting: WebFormsBaseValidatorService }
]
})
@dataTransfer(['customVal'])
@ExceptionHandlerClass(ErrorCodes.Winforms)
export class CustomValidatorComponent extends BaseValidatorComponent {
/**
* Arrow function to evaluate the expression of the attached component.
*
* @private
* @param {string} expression
* @memberof CustomValidatorComponent
*/
@Input()
private clientValidationFunction = (expression: string): boolean => {
return true;
};
/**
* Creates an instance of CustomValidatorComponent.
*
* @param {WebMapService} wmService
* @param {ChangeDetectorRef} refChange
* @param {Renderer2} render2
* @param {ElementRef} elem
* @param {WebComponentsService} webComponents
* @param {BringTopService} bringTopServ1
* @memberof CustomValidatorComponent
*/
constructor(
private wmService: WebMapService,
refChange: ChangeDetectorRef,
render2: Renderer2,
elem: ElementRef,
webComponents: WebComponentsService,
validatorService: BaseValidatorService,
@Optional() bringTopServ1: BringTopService
) {
super(
refChange,
render2,
elem,
webComponents,
validatorService,
bringTopServ1
);
}
/**
* Executes the clientValidationFunction to validate the component attached.
*
* @param {string} controlToValidateId
* @param {string} expression
* @return {*} {boolean}
* @memberof CustomValidatorComponent
*/
validateControl(controlToValidateId: string, expression: string): boolean {
this.validationSuccessInternal = this.clientValidationFunction(expression);
if (this.Display !== ValidatorDisplay.None) {
this.hidden = this.validationSuccessInternal;
} else {
this.hidden = true;
}
return this.validationSuccessInternal;
}
}
<span [hidden]="hidden" [ngClass]="class">{{displayMessage()}}</span>
./custom-validator.component.scss