Skip to content

Commit 5aaa468

Browse files
committed
feat(*): adding external validator logic for input
1 parent d43439d commit 5aaa468

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

projects/igniteui-angular/src/lib/combo/combo.common.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,6 +1300,10 @@ export abstract class IgxComboBaseDirective implements IgxComboBase, AfterViewCh
13001300
this.manageRequiredAsterisk();
13011301
};
13021302

1303+
protected externalValidate(): IgxInputState {
1304+
return this._valid;
1305+
}
1306+
13031307
private updateValidity() {
13041308
if (this.ngControl && this.ngControl.invalid) {
13051309
this.valid = IgxInputState.INVALID;

projects/igniteui-angular/src/lib/combo/combo.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<ng-content select="igx-hint, [igxHint]"></ng-content>
1010
</ng-container>
1111
<input igxInput #comboInput name="comboInput" type="text" [value]="displayValue" readonly
12-
[attr.required]="required"
12+
[externalValidate]="externalValidate"
1313
[attr.placeholder]="placeholder" [disabled]="disabled"
1414
role="combobox" aria-haspopup="listbox"
1515
[attr.aria-expanded]="!dropdown.collapsed" [attr.aria-controls]="dropdown.listId"

projects/igniteui-angular/src/lib/directives/input/input.directive.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ export class IgxInputDirective implements AfterViewInit, OnDestroy {
102102
private _valueChanges$: Subscription;
103103
private _fileNames: string;
104104
private _disabled = false;
105+
private _externalValidate: () => IgxInputState = null;
105106

106107
constructor(
107108
public inputGroup: IgxInputGroupBase,
@@ -195,6 +196,20 @@ export class IgxInputDirective implements AfterViewInit, OnDestroy {
195196
this.nativeElement.required = this.inputGroup.isRequired = value;
196197
}
197198

199+
/**
200+
* @hidden @internal
201+
* Sets a function to validate the input externally.
202+
* This function should return an `IgxInputState` value.
203+
*/
204+
@Input()
205+
public set externalValidate(fn: () => IgxInputState) {
206+
this._externalValidate = fn;
207+
}
208+
209+
public get externalValidate(): () => IgxInputState {
210+
return this._externalValidate;
211+
}
212+
198213
/**
199214
* Gets whether the igxInput is required.
200215
*
@@ -367,7 +382,9 @@ export class IgxInputDirective implements AfterViewInit, OnDestroy {
367382
* @internal
368383
*/
369384
protected updateValidityState() {
370-
if (this.ngControl) {
385+
if (this._externalValidate) {
386+
this._valid = this._externalValidate();
387+
} else if (this.ngControl) {
371388
if (!this.disabled && this.isTouchedOrDirty) {
372389
if (this.hasValidators) {
373390
// Run the validation with empty object to check if required is enabled.

0 commit comments

Comments
 (0)