From b48af601e143198f097f5a6d15819de1c251b344 Mon Sep 17 00:00:00 2001 From: gedinakova Date: Wed, 9 Jan 2019 19:26:37 +0200 Subject: [PATCH] fix(igxInput): #3550 Setting required input value updates valid state. --- .../src/lib/directives/input/input.directive.spec.ts | 12 +++++++++++- .../src/lib/directives/input/input.directive.ts | 3 +++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/projects/igniteui-angular/src/lib/directives/input/input.directive.spec.ts b/projects/igniteui-angular/src/lib/directives/input/input.directive.spec.ts index ca9d1e0ccab..399cede3c4a 100644 --- a/projects/igniteui-angular/src/lib/directives/input/input.directive.spec.ts +++ b/projects/igniteui-angular/src/lib/directives/input/input.directive.spec.ts @@ -193,7 +193,7 @@ describe('IgxInput', () => { testRequiredValidation(inputElement, fixture); }); - fit('Should update style when required input\'s value is set.', () => { + it('Should update style when required input\'s value is set.', () => { const fixture = TestBed.createComponent(RequiredInputComponent); fixture.detectChanges(); @@ -212,6 +212,16 @@ describe('IgxInput', () => { expect(inputGroupElement.classList.contains(INPUT_GROUP_INVALID_CSS_CLASS)).toBe(false); expect(igxInput.valid).toBe(IgxInputState.VALID); + + + igxInput.value = ''; + fixture.detectChanges(); + + dispatchInputEvent('focus', inputElement, fixture); + dispatchInputEvent('blur', inputElement, fixture); + + expect(inputGroupElement.classList.contains(INPUT_GROUP_INVALID_CSS_CLASS)).toBe(true); + expect(igxInput.valid).toBe(IgxInputState.INVALID); }); it('Should style required input with two-way databinding correctly.', () => { diff --git a/projects/igniteui-angular/src/lib/directives/input/input.directive.ts b/projects/igniteui-angular/src/lib/directives/input/input.directive.ts index e522ffe60cd..ed7717e64c9 100644 --- a/projects/igniteui-angular/src/lib/directives/input/input.directive.ts +++ b/projects/igniteui-angular/src/lib/directives/input/input.directive.ts @@ -52,6 +52,9 @@ export class IgxInputDirective implements AfterViewInit, OnDestroy { @Input('value') set value(value: any) { this.nativeElement.value = value; + if (!this.ngControl && this._hasValidators) { + this._valid = this.nativeElement.checkValidity() ? IgxInputState.VALID : IgxInputState.INVALID; + } } /** * Gets the `value` propery.