File

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

Description

Angular Component for the CompareValidator Control.

Extends

BaseValidatorComponent

Implements

OnInit

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 CompareValidatorComponent.

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

controlToCompare
Type : string

Set/Gets the controlToCompare property.

operator
Type : string

Set/Gets the operator property.

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

applyComparation
applyComparation()

Compare the attached controls.

Returns : boolean

{boolean}

ngOnInit
ngOnInit()
Inherited from BaseValidatorComponent

OnInit lifecycle hook, adds itself to the service.

Returns : void
validateControl
validateControl(controlToValidate: string, expressionToValidate: ValidationDataType)
Inherited from BaseValidatorComponent

Compare the two controls attached.

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

the result of the validation.

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

Properties

Private controlToCompareInternal
Type : string
Default value : ''

Property with the controlToCompare id.

Private controlToCompareValue
Type : ValidationDataType
Default value : ''

Property with the controlToCompareValue.

Private controlToValidateValue
Type : ValidationDataType
Default value : ''

Property with the controlToValidateValue.

Private operatorInternal
Type : string
Default value : 'Equal'

Property with the operator

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

controlToCompare
getcontrolToCompare()
setcontrolToCompare(value: string)

Set/Gets the controlToCompare property.

Parameters :
Name Type Optional
value string No
Returns : void
operator
getoperator()
setoperator(value: string)

Set/Gets the operator property.

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

/**
 * Types allowed for validation.
 */
type ValidationDataType = string | number | Date;

/**
 * Angular Component for the CompareValidator Control.
 *
 * @export
 * @class CompareValidatorComponent
 * @extends {BaseValidatorComponent}
 */
@Component({
  selector: 'wm-compare-validator',
  templateUrl: './compare-validator.component.html',
  styleUrls: ['./compare-validator.component.scss'],
  inputs: ['model'],
  providers: [
    { provide: BaseValidatorService, useExisting: WebFormsBaseValidatorService }
  ]
})
@dataTransfer(['compVal'])
@ExceptionHandlerClass(ErrorCodes.Winforms)
export class CompareValidatorComponent
  extends BaseValidatorComponent
  implements OnInit
{
  /**
   * Property with the controlToCompare id.
   *
   * @private
   * @type {string}
   * @memberof CompareValidatorComponent
   */
  private controlToCompareInternal = '';

  /**
   * Property with the controlToValidateValue.
   *
   * @private
   * @type {(string | number | Date)}
   * @memberof CompareValidatorComponent
   */
  private controlToValidateValue: ValidationDataType = '';

  /**
   * Property with the controlToCompareValue.
   *
   * @private
   * @type {(string | number | Date)}
   * @memberof CompareValidatorComponent
   */
  private controlToCompareValue: ValidationDataType = '';

  /**
   *Property with the operator
   *
   * @private
   * @memberof CompareValidatorComponent
   */
  private operatorInternal = 'Equal';

  /**
   * Creates an instance of CompareValidatorComponent.
   *
   * @param {WebMapService} wmService
   * @param {ChangeDetectorRef} refChange
   * @param {Renderer2} render2
   * @param {ElementRef} elem
   * @param {WebComponentsService} webComponents
   * @param {BringTopService} bringTopServ1
   * @memberof CompareValidatorComponent
   */
  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;
  }

  /**
   * OnInit lifecycle hook, adds itself to the service.
   *
   * @memberof CompareValidatorComponent
   */
  ngOnInit() {
    this.validatorService.addCompareValidator(this.controlToCompare, this);
  }

  /**
   *Set/Gets the controlToCompare property.
   *
   * @memberof CompareValidatorComponent
   */
  @Input()
  set controlToCompare(value: string) {
    this.controlToCompareInternal = value;
  }

  get controlToCompare() {
    return this.model.ControlToCompare ?? this.controlToCompareInternal;
  }

  /**
   *Set/Gets the operator property.
   *
   * @memberof CompareValidatorComponent
   */
  @Input()
  set operator(value: string) {
    this.operatorInternal = value;
  }

  get operator() {
    return this.model.Operator ?? this.operatorInternal;
  }

  /**
   * Compare the two controls attached.
   *
   * @param {string} controlToValidate
   * @param {string} expressionToValidate
   * @return the result of the validation.
   * @memberof CompareValidatorComponent
   */
  validateControl(
    controlToValidate: string,
    expressionToValidate: ValidationDataType
  ): boolean {
    if (controlToValidate === this.controlToValidate) {
      this.controlToValidateValue = expressionToValidate;
    } else {
      this.controlToCompareValue = expressionToValidate;
    }

    this.validationSuccessInternal = this.applyComparation();

    if (this.Display !== ValidatorDisplay.None) {
      this.hidden = this.validationSuccessInternal;
    } else {
      this.hidden = true;
    }

    return this.validationSuccessInternal;
  }

  /**
   * Compare the attached controls.
   *
   * @return {*}  {boolean}
   * @memberof CompareValidatorComponent
   */
  applyComparation(): boolean {
    let validation: boolean;
    switch (this.operator) {
      case 'NotEqual':
        validation = this.controlToValidateValue !== this.controlToCompareValue;
        break;
      case 'GreaterThan':
        validation = this.controlToValidateValue > this.controlToCompareValue;
        break;
      case 'GreaterThanEqual':
        validation = this.controlToValidateValue >= this.controlToCompareValue;
        break;
      case 'LessThan':
        validation = this.controlToValidateValue < this.controlToCompareValue;
        break;
      case 'LessThanEqual':
        validation = this.controlToValidateValue <= this.controlToCompareValue;
        break;
      default:
        validation = this.controlToValidateValue === this.controlToCompareValue;
        break;
    }
    return validation;
  }
}
<span [hidden]="hidden" [ngClass]="class">{{displayMessage()}}</span>

./compare-validator.component.scss

Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""