File

src/lib/components/regular-expression-validator/regular-expression-validator.component.ts

Description

Angular Component for the Regular Expression Validator Control.

Extends

BaseValidatorComponent

Metadata

Index

Properties
Methods
Inputs
Accessors

Constructor

constructor(wmService: WebMapService, refChange: ChangeDetectorRef, render2: Renderer2, elem: ElementRef, webComponents: WebComponentsService, validatorService: BaseValidatorService, bringTopServ1: BringTopService)

Creates an instance of RegularExpressionValidatorComponent.

Parameters :
Name Type Optional
wmService WebMapService No
refChange ChangeDetectorRef No
render2 Renderer2 No
elem ElementRef No
webComponents WebComponentsService No
validatorService BaseValidatorService No
bringTopServ1 BringTopService No

Inputs

validationExpression
Type : string

Gets/sets the validation expression.

controlToValidate
Type : string
Inherited from BaseValidatorComponent

Gets/sets the Control to Validate and notify the service.

errorMessage
Type : string
Inherited from BaseValidatorComponent

Gets/sets the error message.

Methods

validateControl
validateControl(controlToValidate: string, expressionToValidate: string)
Inherited from BaseValidatorComponent

Match the regular expression with the expressionToValidate

Parameters :
Name Type Optional
controlToValidate string No
expressionToValidate string No
Returns : boolean

if the validation expression match the regular expression

displayMessage
displayMessage()
Inherited from BaseValidatorComponent

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

OnDestroy lifecycle hook, removes itself from the service.

Returns : void
ngOnInit
ngOnInit()
Inherited from BaseValidatorComponent

OnInit lifecycle hook, adds itself to the service.

Returns : void

Properties

Private validationExpressionInternal
Type : string
Default value : ''

Property with the REGEX to match.

Protected controlToValidateInternal
Type : string
Default value : ''
Inherited from BaseValidatorComponent

Property with the Id of the control to validate.

Private displayInternal
Default value : ValidatorDisplay.Static
Inherited from BaseValidatorComponent

Internal property for handle type of Display in component

Protected errorMessageInternal
Type : string
Default value : ''
Inherited from BaseValidatorComponent

Property with the error message.

Protected hiddenInternal
Default value : true
Inherited from BaseValidatorComponent

Property with the visibility of the component.

Protected validationGroupInternal
Type : string
Default value : ''
Inherited from BaseValidatorComponent

Property with the validationGroup

@memberof BaseValidatorComponent

Protected validationSuccessInternal
Default value : false
Inherited from BaseValidatorComponent

Property with that indicates if the validation is passed.

Accessors

validationExpression
getvalidationExpression()
setvalidationExpression(regularExpression: string)

Gets/sets the validation expression.

Parameters :
Name Type Optional
regularExpression string No
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

Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""