File

src/lib/components/base-validator/BaseValidator.ts

Extends

ControlComponent

Implements

OnDestroy OnInit

Metadata

Index

Properties
Methods
Inputs
Accessors

Constructor

constructor(refChange: ChangeDetectorRef, render2: Renderer2, elem: ElementRef, webComponents: WebComponentsService, validatorService: BaseValidatorService, bringTopServ1: BringTopService)
Parameters :
Name Type Optional
refChange ChangeDetectorRef No
render2 Renderer2 No
elem ElementRef No
webComponents WebComponentsService No
validatorService BaseValidatorService No
bringTopServ1 BringTopService No

Inputs

controlToValidate
Type : string

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

errorMessage
Type : string

Gets/sets the error message.

Methods

displayMessage
displayMessage()

If the text property is defined, it has to be shown instead of the error message

Returns : string

The property to display

ngOnDestroy
ngOnDestroy()

OnDestroy lifecycle hook, removes itself from the service.

Returns : void
ngOnInit
ngOnInit()

OnInit lifecycle hook, adds itself to the service.

Returns : void
validateControl
validateControl(controlToValidate: string, validationExpression: string | number | Date)

Execute the validation, has to be overridden by sub-classes.

Parameters :
Name Type Optional
controlToValidate string No
validationExpression string | number | Date No
Returns : boolean

the results of the validation.

Properties

Protected controlToValidateInternal
Type : string
Default value : ''

Property with the Id of the control to validate.

Private displayInternal
Default value : ValidatorDisplay.Static

Internal property for handle type of Display in component

Protected errorMessageInternal
Type : string
Default value : ''

Property with the error message.

Protected hiddenInternal
Default value : true

Property with the visibility of the component.

Protected validationGroupInternal
Type : string
Default value : ''

Property with the validationGroup

@memberof BaseValidatorComponent

Protected validationSuccessInternal
Default value : false

Property with that indicates if the validation is passed.

Accessors

controlToValidate
getcontrolToValidate()
setcontrolToValidate(elementToValidate: string)

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

Parameters :
Name Type Optional
elementToValidate string No
Returns : void
errorMessage
geterrorMessage()
seterrorMessage(errorMessage: string)

Gets/sets the error message.

Parameters :
Name Type Optional
errorMessage string No
Returns : void
hidden
gethidden()
sethidden(state: boolean)

Gets/sets the hidden state.

Parameters :
Name Type Optional
state boolean No
Returns : void
validationSuccess
getvalidationSuccess()

Gets the validation state.

validationGroup
getvalidationGroup()
setvalidationGroup(value: string)

Gets/sets the validationGroup.

Parameters :
Name Type Optional
value string No
Returns : void
Display
getDisplay()
setDisplay(value: ValidatorDisplay)

Display property from model or input if exists

Parameters :
Name Type Optional
value ValidatorDisplay No
Returns : void
import {
  ChangeDetectorRef,
  Component,
  ElementRef,
  Input,
  OnDestroy,
  OnInit,
  Optional,
  Renderer2
} from '@angular/core';
import { BringTopService } from '@mobilize/base-components';
import {
  BaseValidatorService,
  ControlComponent,
  WebComponentsService
} from '@mobilize/winforms-components';
import { ErrorCodes, ExceptionHandlerClass } from '@mobilize/webmap-core';
import { WebFormsBaseValidatorService } from '../../services/base-validator-service/web-forms-base-validator.service';
import { ValidatorDisplay } from '../../contracts/ValidatorDisplay';

@Component({
  templateUrl: './base-validator.component.html',
  styleUrls: ['./base-validator.component.scss'],
  inputs: ['model'],
  providers: [
    { provide: BaseValidatorService, useExisting: WebFormsBaseValidatorService }
  ]
})
@ExceptionHandlerClass(ErrorCodes.Winforms)
export class BaseValidatorComponent
  extends ControlComponent
  implements OnDestroy, OnInit
{
  /**
   * Property with that indicates if the validation is passed.
   *
   * @memberof BaseValidatorComponent
   */
  protected validationSuccessInternal = false;

  /**
   * Property with the visibility of the component.
   *
   * @memberof BaseValidatorComponent
   */
  protected hiddenInternal = true;

  /**
   * Property with the Id of the control to validate.
   *
   * @memberof BaseValidatorComponent
   */
  protected controlToValidateInternal = '';

  /**
   * Property with the error message.
   *
   * @memberof BaseValidatorComponent
   */
  protected errorMessageInternal = '';

  /**
   * Property with the validationGroup
   *
   *  @memberof BaseValidatorComponent
   */
  protected validationGroupInternal = '';

  /**
   * Internal property for handle type of Display in component
   *
   * @private
   * @memberof RequiredFieldValidatorComponent
   */
  private displayInternal = ValidatorDisplay.Static;

  constructor(
    private refChange: ChangeDetectorRef,
    private render2: Renderer2,
    private elem: ElementRef,
    webComponents: WebComponentsService,
    protected validatorService: BaseValidatorService,
    @Optional() private bringTopServ1: BringTopService
  ) {
    super(refChange, render2, elem, webComponents, bringTopServ1);
  }

  /**
   * OnInit lifecycle hook, adds itself to the service.
   *
   * @memberof BaseValidatorComponent
   */
  ngOnInit(): void {
    this.validatorService.addValidator(this);
  }

  /**
   * OnDestroy lifecycle hook, removes itself from the service.
   *
   * @memberof BaseValidatorComponent
   */
  ngOnDestroy() {
    this.validatorService.removeValidator(this);
  }

  /**
   * Gets/sets the Control to Validate and notify the service.
   *
   * @memberof BaseValidatorComponent
   */
  @Input()
  set controlToValidate(elementToValidate: string) {
    this.validatorService.removeValidator(this);
    this.controlToValidateInternal = elementToValidate;
    this.validatorService.addValidator(this);
  }

  get controlToValidate(): string {
    return this.model?.ControlToValidate ?? this.controlToValidateInternal;
  }

  /**
   * Gets/sets the error message.
   *
   * @memberof BaseValidatorComponent
   */
  @Input()
  set errorMessage(errorMessage: string) {
    this.errorMessageInternal = errorMessage;
  }

  get errorMessage() {
    return this.model?.ErrorMessage ?? this.errorMessageInternal;
  }

  /**
   * Gets/sets the hidden state.
   *
   * @memberof BaseValidatorComponent
   */
  set hidden(state: boolean) {
    this.hiddenInternal = state;
  }

  get hidden() {
    return this.hiddenInternal;
  }

  /**
   * Gets the validation state.
   *
   * @memberof BaseValidatorComponent
   */
  get validationSuccess() {
    return this.validationSuccessInternal;
  }

  /**
   * Gets/sets the validationGroup.
   *
   * @memberof BaseValidatorComponent
   */
  set validationGroup(value: string) {
    this.validationGroupInternal = value;
  }

  get validationGroup() {
    return this.model?.ValidationGroup ?? this.validationGroupInternal;
  }

  /**
   * Display property from model or input if exists
   *
   * @readonly
   * @type {string}
   * @memberof GridViewComponent
   */
  set Display(value: ValidatorDisplay) {
    this.displayInternal = value;
  }

  get Display(): ValidatorDisplay {
    return (this.model && this.model.Display) ?? this.displayInternal;
  }

  /**
   * Execute the validation, has to be overridden by sub-classes.
   *
   * @param expressionToValidate
   * @memberof BaseValidatorComponent
   * @returns the results of the validation.
   */
  validateControl(
    controlToValidate: string,
    validationExpression: string | number | Date
  ): boolean {
    return false;
  }

  /**
   * If the text property is defined, it has to be shown instead of the error message
   *
   * @memberof BaseValidatorComponent
   * @returns The property to display
   */
  displayMessage(): string {
    return this.text && this.text != '' ? this.text : this.errorMessage;
  }
}
<span [hidden]="hidden" [ngClass]="class">{{displayMessage()}}</span>

./base-validator.component.scss

Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""