Skip to content

Commit

Permalink
fix(igxInput): #3550 Setting required input value updates valid state.
Browse files Browse the repository at this point in the history
  • Loading branch information
gedinakova committed Jan 10, 2019
1 parent a1b3297 commit d9ecf97
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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.', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit d9ecf97

Please sign in to comment.