src/lib/components/required-field-validator/required-field-validator.component.ts
providers |
{ provide: BaseValidatorService, useExisting: WebFormsBaseValidatorService }
|
selector | wm-required-field-validator |
styleUrls | ./required-field-validator.component.scss |
templateUrl | ./required-field-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 RequiredFieldValidatorComponent.
Parameters :
|
initialValue | |
Type : string
|
|
Gets/sets the initial value. |
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. |
validateControl | |||||||||
validateControl(controlToValidate: string, expressionToValidate: string | number | Date)
|
|||||||||
Inherited from
BaseValidatorComponent
|
|||||||||
Defined in
BaseValidatorComponent:107
|
|||||||||
Compare the expressionToValidate against the initial value to validate that they are different.
Parameters :
Returns :
boolean
if the expressionToValidate is different from the initial value. |
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 initialValueInternal |
Type : string
|
Default value : ''
|
Property with the initial value to validate against |
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. |
initialValue | ||||||
getinitialValue()
|
||||||
setinitialValue(initialValue: string)
|
||||||
Gets/sets the initial value.
Parameters :
Returns :
void
|
import { WebMapService } from '@mobilize/angularclient';
import { BringTopService, dataTransfer } from '@mobilize/base-components';
import {
BaseValidatorService,
WebComponentsService
} from '@mobilize/winforms-components';
import {
Component,
Optional,
ElementRef,
Input,
Renderer2,
ChangeDetectorRef
} from '@angular/core';
import { BaseValidatorComponent } from '../base-validator/BaseValidator';
import { WebFormsBaseValidatorService } from '../../services/base-validator-service/web-forms-base-validator.service';
import { ExceptionHandlerClass, ErrorCodes } from '@mobilize/webmap-core';
import { ValidatorDisplay } from '../../contracts/ValidatorDisplay';
@Component({
selector: 'wm-required-field-validator',
templateUrl: './required-field-validator.component.html',
styleUrls: ['./required-field-validator.component.scss'],
inputs: ['model'],
providers: [
{ provide: BaseValidatorService, useExisting: WebFormsBaseValidatorService }
]
})
@dataTransfer(['requiredVal'])
@ExceptionHandlerClass(ErrorCodes.Winforms)
export class RequiredFieldValidatorComponent extends BaseValidatorComponent {
/**
* Property with the initial value to validate against
*
* @memberof RequiredFieldValidatorComponent
*/
protected initialValueInternal = '';
/**
* Creates an instance of RequiredFieldValidatorComponent.
*
* @param {WebMapService} wmService
* @param {ChangeDetectorRef} refChange
* @param {Renderer2} render2
* @param {ElementRef} elem
* @param {WebComponentsService} webComponents
* @param {BringTopService} bringTopServ1
* @memberof RequiredFieldValidatorComponent
*/
constructor(
private wmService: WebMapService,
refChange: ChangeDetectorRef,
render2: Renderer2,
elem: ElementRef,
webComponents: WebComponentsService,
validatorService: BaseValidatorService,
@Optional() bringTopServ1: BringTopService
) {
super(
refChange,
render2,
elem,
webComponents,
validatorService,
bringTopServ1
);
}
/**
* Gets/sets the initial value.
*
* @memberof RequiredFieldValidatorComponent
*/
@Input()
set initialValue(initialValue: string) {
this.initialValueInternal = initialValue;
}
get initialValue() {
return this.model.InitialValue ?? this.initialValueInternal;
}
/**
* Compare the expressionToValidate against the initial value
* to validate that they are different.
*
* @param expressionToValidate
* @returns if the expressionToValidate is different from the initial value.
* @memberof RequiredFieldValidatorComponent
*/
validateControl(
controlToValidate: string,
expressionToValidate: string | number | Date
): boolean {
this.validationSuccessInternal = expressionToValidate !== this.initialValue;
if (this.Display !== ValidatorDisplay.None) {
this.hidden = this.validationSuccessInternal;
} else {
this.hidden = true;
}
return this.validationSuccessInternal;
}
}
<span [hidden]="hidden" [ngClass]="class">{{displayMessage()}}</span>
./required-field-validator.component.scss