Skip to content

Commit d97a541

Browse files
committed
chore(input): add shouldCheckValidy
Also force setting of this.validy to pass trouth setter always
1 parent 5c2b2d1 commit d97a541

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

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

+17-13
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,18 @@ export class IgxInputDirective implements AfterViewInit, OnDestroy {
134134
if (typeof value === 'boolean') {
135135
this.nativeElement.required = this.inputGroup.isRequired = value;
136136

137-
if (value && !this.nativeElement.checkValidity()) {
138-
this._valid = IgxInputState.INVALID;
137+
if (value && !this.nativeElement.checkValidity() && this.shouldCheckValidity) {
138+
this.valid = IgxInputState.INVALID;
139139
} else {
140-
this._valid = IgxInputState.INITIAL;
140+
this.valid = IgxInputState.INITIAL;
141141
}
142142
}
143143
}
144144

145+
/** @hidden @internal */
146+
@Input()
147+
public shouldCheckValidity = true;
148+
145149
/**
146150
* Gets whether the igxInput is required.
147151
*
@@ -203,13 +207,13 @@ export class IgxInputDirective implements AfterViewInit, OnDestroy {
203207
@HostListener('blur', ['$event'])
204208
public onBlur(event) {
205209
this.inputGroup.isFocused = false;
206-
this._valid = IgxInputState.INITIAL;
210+
this.valid = IgxInputState.INITIAL;
207211
if (this.ngControl) {
208212
if (!this.ngControl.valid) {
209-
this._valid = IgxInputState.INVALID;
213+
this.valid = IgxInputState.INVALID;
210214
}
211-
} else if (this._hasValidators() && !this.nativeElement.checkValidity()) {
212-
this._valid = IgxInputState.INVALID;
215+
} else if (this._hasValidators() && !this.nativeElement.checkValidity() && this.shouldCheckValidity) {
216+
this.valid = IgxInputState.INVALID;
213217
}
214218
}
215219
/**
@@ -231,7 +235,7 @@ export class IgxInputDirective implements AfterViewInit, OnDestroy {
231235

232236
// Make sure we do not invalidate the input on init
233237
if (!this.ngControl) {
234-
this._valid = IgxInputState.INITIAL;
238+
this.valid = IgxInputState.INITIAL;
235239
}
236240
// Also check the control's validators for required
237241
if (!this.inputGroup.isRequired && this.ngControl && this.ngControl.control.validator) {
@@ -294,15 +298,15 @@ export class IgxInputDirective implements AfterViewInit, OnDestroy {
294298
// TODO: check the logic when control is touched or dirty
295299
if (this.inputGroup.isFocused) {
296300
// the user is still typing in the control
297-
this._valid = this.ngControl.valid ? IgxInputState.VALID : IgxInputState.INVALID;
301+
this.valid = this.ngControl.valid ? IgxInputState.VALID : IgxInputState.INVALID;
298302
} else {
299303
// the user had touched the control previously but now the value is changing due to changes in the form
300-
this._valid = this.ngControl.valid ? IgxInputState.INITIAL : IgxInputState.INVALID;
304+
this.valid = this.ngControl.valid ? IgxInputState.INITIAL : IgxInputState.INVALID;
301305
}
302306
} else {
303307
// if control is untouched and pristine its state is initial. This is when user did not interact
304308
// with the input or when form/control is reset
305-
this._valid = IgxInputState.INITIAL;
309+
this.valid = IgxInputState.INITIAL;
306310
}
307311
}
308312
}
@@ -399,8 +403,8 @@ export class IgxInputDirective implements AfterViewInit, OnDestroy {
399403
* @internal
400404
*/
401405
private checkValidity() {
402-
if (!this.ngControl && this._hasValidators()) {
403-
this._valid = this.nativeElement.checkValidity() ? IgxInputState.VALID : IgxInputState.INVALID;
406+
if (!this.ngControl && this._hasValidators() && this.shouldCheckValidity) {
407+
this.valid = this.nativeElement.checkValidity() ? IgxInputState.VALID : IgxInputState.INVALID;
404408
}
405409
}
406410
}

0 commit comments

Comments
 (0)