src/lib/components/compare-validator/compare-validator.component.ts
Angular Component for the CompareValidator Control.
providers |
{ provide: BaseValidatorService, useExisting: WebFormsBaseValidatorService }
|
selector | wm-compare-validator |
styleUrls | ./compare-validator.component.scss |
templateUrl | ./compare-validator.component.html |
Properties |
|
Methods |
Inputs |
Accessors |
constructor(wmService: WebMapService, refChange: ChangeDetectorRef, render2: Renderer2, elem: ElementRef, webComponents: WebComponentsService, validatorService: BaseValidatorService, bringTopServ1: BringTopService)
|
||||||||||||||||||||||||
Creates an instance of CompareValidatorComponent.
Parameters :
|
controlToCompare | |
Type : string
|
|
Set/Gets the controlToCompare property. |
operator | |
Type : string
|
|
Set/Gets the operator property. |
controlToValidate | |
Type : string
|
|
Inherited from
BaseValidatorComponent
|
|
Defined in
BaseValidatorComponent:130
|
|
Gets/sets the Control to Validate and notify the service. |
errorMessage | |
Type : string
|
|
Inherited from
BaseValidatorComponent
|
|
Defined in
BaseValidatorComponent:146
|
|
Gets/sets the error message. |
applyComparation |
applyComparation()
|
Compare the attached controls.
Returns :
boolean
{boolean} |
ngOnInit |
ngOnInit()
|
Inherited from
BaseValidatorComponent
|
Defined in
BaseValidatorComponent:135
|
OnInit lifecycle hook, adds itself to the service.
Returns :
void
|
validateControl | |||||||||
validateControl(controlToValidate: string, expressionToValidate: ValidationDataType)
|
|||||||||
Inherited from
BaseValidatorComponent
|
|||||||||
Defined in
BaseValidatorComponent:175
|
|||||||||
Compare the two controls attached.
Parameters :
Returns :
boolean
the result of the validation. |
displayMessage |
displayMessage()
|
Inherited from
BaseValidatorComponent
|
Defined in
BaseValidatorComponent:224
|
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
|
Defined in
BaseValidatorComponent:120
|
OnDestroy lifecycle hook, removes itself from the service.
Returns :
void
|
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
|
Defined in
BaseValidatorComponent:71
|
Property with the Id of the control to validate. |
Private displayInternal |
Default value : ValidatorDisplay.Static
|
Inherited from
BaseValidatorComponent
|
Defined in
BaseValidatorComponent:93
|
Internal property for handle type of Display in component |
Protected errorMessageInternal |
Type : string
|
Default value : ''
|
Inherited from
BaseValidatorComponent
|
Defined in
BaseValidatorComponent:78
|
Property with the error message. |
Protected hiddenInternal |
Default value : true
|
Inherited from
BaseValidatorComponent
|
Defined in
BaseValidatorComponent:64
|
Property with the visibility of the component. |
Protected validationGroupInternal |
Type : string
|
Default value : ''
|
Inherited from
BaseValidatorComponent
|
Defined in
BaseValidatorComponent:85
|
Property with the validationGroup @memberof BaseValidatorComponent |
Protected validationSuccessInternal |
Default value : false
|
Inherited from
BaseValidatorComponent
|
Defined in
BaseValidatorComponent:57
|
Property with that indicates if the validation is passed. |
controlToCompare | ||||||
getcontrolToCompare()
|
||||||
setcontrolToCompare(value: string)
|
||||||
Set/Gets the controlToCompare property.
Parameters :
Returns :
void
|
operator | ||||||
getoperator()
|
||||||
setoperator(value: string)
|
||||||
Set/Gets the operator property.
Parameters :
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