File

src/lib/components/custom-validator/custom-validator.component.ts

Description

Angular Component for the CustomValidator Control.

Extends

BaseValidatorComponent

Metadata

Index

Properties
Methods
Inputs

Constructor

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

Creates an instance of CustomValidatorComponent.

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

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

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

errorMessage
Type : string
Inherited from BaseValidatorComponent

Gets/sets the error message.

Methods

validateControl
validateControl(controlToValidateId: string, expression: string)
Inherited from BaseValidatorComponent

Executes the clientValidationFunction to validate the component attached.

Parameters :
Name Type Optional
controlToValidateId string No
expression string No
Returns : boolean

{boolean}

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

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.

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

Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""