File

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

Description

Angular Component for the RangeValidator 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 RangeValidatorComponent.

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

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

Private between
between(target: any, min: any, max: any)

Between range the current target.

Parameters :
Name Type Optional Description
target any No

The target value to validate.

min any No

The minimun value.

max any No

The maximun value.

Returns : boolean

true if between.

Private convertToCurrentType
convertToCurrentType(value: string)

Converts the current value to current type.

Parameters :
Name Type Optional Description
value string No

The value to convert.

Returns : any

The converted value.

Private IsValidValue
IsValidValue(value: any)

Determines whether value is valid according the data type.

Parameters :
Name Type Optional Description
value any No

The value to validate.

Returns : boolean

true if valid value.

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

Validates control.

Parameters :
Name Type Optional Description
controlToValidate string No

The control to validate.

validationExpression string No

The current expression.

Returns : boolean

true if control passes 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
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.

Accessors

minimumValue
getminimumValue()

Gets minimun value.

Returns : string
setminimumValue(value: string)

Sets minimun value.

Parameters :
Name Type Optional
value string No
Returns : void
maximumValue
getmaximumValue()

Gets minimun value.

Returns : string
setmaximumValue(value: string)

Sets minimun value.

Parameters :
Name Type Optional
value string No
Returns : void
type
gettype()

Gets type.

Returns : ValidationDataType
settype(value: ValidationDataType)

Sets type.

Parameters :
Name Type Optional
value ValidationDataType No
Returns : void
import {
  ChangeDetectorRef,
  Component,
  ElementRef,
  Optional,
  Renderer2
} from '@angular/core';
import { dataTransfer, BringTopService } from '@mobilize/base-components';
import { WebMapService } from '@mobilize/angularclient';
import {
  BaseValidatorService,
  WebComponentsService
} from '@mobilize/winforms-components';
import { BaseValidatorComponent } from '../base-validator/BaseValidator';
import { WebFormsBaseValidatorService } from '../../services/base-validator-service/web-forms-base-validator.service';
import { ValidationDataType } from '../validation-data-type/ValidationDataType.enum';

/**
 * Angular Component for the RangeValidator Control.
 *
 * @export
 * @class RangeValidatorComponent
 * @extends {BaseValidatorComponent}
 */
@Component({
  selector: 'wm-range-validator',
  templateUrl: './range-validator.component.html',
  styleUrls: ['./range-validator.component.scss'],
  inputs: ['model'],
  providers: [
    {
      provide: BaseValidatorService,
      useExisting: WebFormsBaseValidatorService
    }
  ]
})
@dataTransfer(['rngval'])
export class RangeValidatorComponent extends BaseValidatorComponent {
  /**
   * Creates an instance of RangeValidatorComponent.
   *
   * @param {WebMapService} wmService
   * @param {ChangeDetectorRef} refChange
   * @param {Renderer2} render2
   * @param {ElementRef} elem
   * @param {WebComponentsService} webComponents
   * @param {BringTopService} bringTopServ1
   * @memberof RangeValidatorComponent
   */
  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 minimun value.
   */
  /* c8 ignore next 3 */
  get minimumValue(): string {
    return this.model.MinimumValue;
  }

  /**
   * Sets minimun value.
   */
  /* c8 ignore next 3 */
  set minimumValue(value: string) {
    this.model.MinimumValue = value;
  }

  /**
   * Gets minimun value.
   */
  /* c8 ignore next 3 */
  get maximumValue(): string {
    return this.model.MaximumValue;
  }

  /**
   * Sets minimun value.
   */
  /* c8 ignore next 3 */
  set maximumValue(value: string) {
    this.model.MaximumValue = value;
  }

  /**
   * Gets type.
   */
  /* c8 ignore next 3 */
  get type(): ValidationDataType {
    return this.model.Type;
  }

  /**
   * Sets type.
   */
  /* c8 ignore next 3 */
  set type(value: ValidationDataType) {
    this.model.Type = value;
  }

  /**
   * Validates control.
   * @param controlToValidate The control to validate.
   * @param validationExpression The current expression.
   * @returns true if control passes the validation
   */
  validateControl(
    controlToValidate: string,
    validationExpression: string
  ): boolean {
    const target = this.convertToCurrentType(validationExpression);
    const minimun = this.convertToCurrentType(this.minimumValue);
    const maximum = this.convertToCurrentType(this.maximumValue);
    if (
      this.IsValidValue(target) &&
      this.IsValidValue(minimun) &&
      this.IsValidValue(maximum) &&
      this.between(target, minimun, maximum)
    ) {
      this.hidden = true;
      this.validationSuccessInternal = true;
    } else {
      this.hidden = false;
      this.validationSuccessInternal = false;
    }

    return this.hidden;
  }

  /**
   * Determines whether value is valid according the data type.
   * @param value The value to validate.
   * @returns true if valid value.
   */
  private IsValidValue(value: any): boolean {
    switch (this.type) {
      case ValidationDataType.Currency:
      case ValidationDataType.Double:
      case ValidationDataType.Integer:
        return !isNaN(value);
      default:
        return value != undefined;
    }
  }

  /**
   * Between range the current target.
   * @param target The target value to validate.
   * @param min The minimun value.
   * @param max The maximun value.
   * @returns true if between.
   */
  private between(target: any, min: any, max: any): boolean {
    return target >= min && target <= max;
  }

  /**
   * Converts the current value to current type.
   * @param value The value to convert.
   * @returns  The converted value.
   */
  private convertToCurrentType(value: string) {
    switch (this.type) {
      case ValidationDataType.Currency:
      case ValidationDataType.Double:
        return parseFloat(value);
      case ValidationDataType.Integer:
        return parseInt(value);
      case ValidationDataType.Date:
        return new Date(value);
      default:
        return value;
    }
  }
}
<span [hidden]="hidden" [ngClass]="class">{{displayMessage()}}</span>

./range-validator.component.scss

Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""