src/lib/components/regular-expression-validator/regular-expression-validator.component.ts
Angular Component for the Regular Expression Validator Control.
providers |
{ provide: BaseValidatorService, useExisting: WebFormsBaseValidatorService }
|
selector | wm-regular-expression-validator |
styleUrls | ./regular-expression-validator.component.scss |
templateUrl | ./regular-expression-validator.component.html |
Properties |
|
Methods |
Inputs |
Accessors |
constructor(wmService: WebMapService, refChange: ChangeDetectorRef, render2: Renderer2, elem: ElementRef, webComponents: WebComponentsService, validatorService: BaseValidatorService, bringTopServ1: BringTopService)
|
||||||||||||||||||||||||
Creates an instance of RegularExpressionValidatorComponent.
Parameters :
|
validationExpression | |
Type : string
|
|
Gets/sets the validation expression. |
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(controlToValidate: string, expressionToValidate: string)
|
Inherited from
BaseValidatorComponent
|
Defined in
BaseValidatorComponent:114
|
Match the regular expression with the expressionToValidate
Returns :
boolean
if the validation expression match the regular expression |
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
|
Private validationExpressionInternal |
Type : string
|
Default value : ''
|
Property with the REGEX to match. |
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. |
validationExpression | ||||||
getvalidationExpression()
|
||||||
setvalidationExpression(regularExpression: string)
|
||||||
Gets/sets the validation expression.
Parameters :
Returns :
void
|
import {
Optional,
ChangeDetectorRef,
Component,
Input,
ElementRef,
Renderer2
} from '@angular/core';
import { WebFormsBaseValidatorService } from '../../services/base-validator-service/web-forms-base-validator.service';
import { WebMapService } from '@mobilize/angularclient';
import { dataTransfer, BringTopService } from '@mobilize/base-components';
import {
BaseValidatorService,
WebComponentsService
} from '@mobilize/winforms-components';
import { BaseValidatorComponent } from '../base-validator/BaseValidator';
import { ErrorCodes, ExceptionHandlerClass } from '@mobilize/webmap-core';
import { ValidatorDisplay } from '../../contracts/ValidatorDisplay';
/**
* Angular Component for the Regular Expression Validator Control.
*
* @export
* @class RegularExpressionValidatorComponent
* @extends {ControlComponent}
*/
@Component({
selector: 'wm-regular-expression-validator',
templateUrl: './regular-expression-validator.component.html',
styleUrls: ['./regular-expression-validator.component.scss'],
inputs: ['model'],
providers: [
{ provide: BaseValidatorService, useExisting: WebFormsBaseValidatorService }
]
})
@dataTransfer(['regexVal'])
@ExceptionHandlerClass(ErrorCodes.Winforms)
export class RegularExpressionValidatorComponent extends BaseValidatorComponent {
/**
* Property with the REGEX to match.
*
* @memberof RegularExpressionValidatorComponent
*/
private validationExpressionInternal = '';
/**
* Creates an instance of RegularExpressionValidatorComponent.
*
* @param {WebMapService} wmService
* @param {ChangeDetectorRef} refChange
* @param {Renderer2} render2
* @param {ElementRef} elem
* @param {WebComponentsService} webComponents
* @param {BringTopService} bringTopServ1
* @memberof RegularExpressionValidatorComponent
*/
constructor(
private wmService: WebMapService,
refChange: ChangeDetectorRef,
render2: Renderer2,
elem: ElementRef,
webComponents: WebComponentsService,
validatorService: BaseValidatorService,
@Optional() bringTopServ1: BringTopService
) {
super(
refChange,
render2,
elem,
webComponents,
validatorService,
bringTopServ1
);
this.validationSuccessInternal = true;
}
/**
* Gets/sets the validation expression.
*
* @memberof RegularExpressionValidatorComponent
*/
@Input()
set validationExpression(regularExpression: string) {
this.validationExpressionInternal = regularExpression;
}
get validationExpression() {
return this.model.ValidationExpression ?? this.validationExpressionInternal;
}
/**
* Match the regular expression with the expressionToValidate
*
* @param expressionToValidate
* @returns if the validation expression match the regular expression
* @memberof RegularExpressionValidatorComponent
*/
validateControl(
controlToValidate: string,
expressionToValidate: string
): boolean {
const matches = expressionToValidate.match(this.validationExpression);
this.validationSuccessInternal =
(matches != null && matches[0] === expressionToValidate) ||
expressionToValidate === '';
if (this.Display !== ValidatorDisplay.None) {
this.hidden = this.validationSuccessInternal;
} else {
this.hidden = true;
}
return this.validationSuccessInternal;
}
}
<span [hidden]="hidden" [ngClass]="class">{{displayMessage()}}</span>
./regular-expression-validator.component.scss