src/lib/components/range-validator/range-validator.component.ts
Angular Component for the RangeValidator Control.
providers |
{
provide: BaseValidatorService, useExisting: WebFormsBaseValidatorService
}
|
selector | wm-range-validator |
styleUrls | ./range-validator.component.scss |
templateUrl | ./range-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 RangeValidatorComponent.
Parameters :
|
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. |
Private between | ||||||||||||||||
between(target: any, min: any, max: any)
|
||||||||||||||||
Between range the current target.
Parameters :
Returns :
boolean
true if between. |
Private convertToCurrentType | ||||||||
convertToCurrentType(value: string)
|
||||||||
Converts the current value to current type.
Parameters :
Returns :
any
The converted value. |
Private IsValidValue | ||||||||
IsValidValue(value: any)
|
||||||||
Determines whether value is valid according the data type.
Parameters :
Returns :
boolean
true if valid value. |
validateControl | ||||||||||||
validateControl(controlToValidate: string, validationExpression: string)
|
||||||||||||
Inherited from
BaseValidatorComponent
|
||||||||||||
Defined in
BaseValidatorComponent:124
|
||||||||||||
Validates control.
Parameters :
Returns :
boolean
true if control passes 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
|
ngOnInit |
ngOnInit()
|
Inherited from
BaseValidatorComponent
|
Defined in
BaseValidatorComponent:111
|
OnInit lifecycle hook, adds itself to the service.
Returns :
void
|
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. |
minimumValue | ||||||
getminimumValue()
|
||||||
Gets minimun value.
Returns :
string
|
||||||
setminimumValue(value: string)
|
||||||
Sets minimun value.
Parameters :
Returns :
void
|
maximumValue | ||||||
getmaximumValue()
|
||||||
Gets minimun value.
Returns :
string
|
||||||
setmaximumValue(value: string)
|
||||||
Sets minimun value.
Parameters :
Returns :
void
|
type | ||||||
gettype()
|
||||||
Gets type.
Returns :
ValidationDataType
|
||||||
settype(value: ValidationDataType)
|
||||||
Sets type.
Parameters :
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