Skip to content

Commit 6dee405

Browse files
authored
Merge pull request #12906 from IgniteUI/thristodorova/fix-12895-15.1.x
fix(IgxInputDirective): Calculate required value when input is bound via formControl
2 parents 0c6cce3 + dbf6f47 commit 6dee405

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

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

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Component, ViewChild, ViewChildren, QueryList, DebugElement } from '@angular/core';
22
import { TestBed, fakeAsync, tick, waitForAsync } from '@angular/core/testing';
3-
import { FormsModule, UntypedFormBuilder, ReactiveFormsModule, Validators, UntypedFormControl, UntypedFormGroup } from '@angular/forms';
3+
import { FormsModule, UntypedFormBuilder, ReactiveFormsModule, Validators, UntypedFormControl, UntypedFormGroup, FormControl } from '@angular/forms';
44
import { By } from '@angular/platform-browser';
55
import { IgxInputGroupComponent, IgxInputGroupModule } from '../../input-group/input-group.component';
66
import { IgxInputDirective, IgxInputState } from './input.directive';
@@ -266,10 +266,10 @@ describe('IgxInput', () => {
266266
fixture.detectChanges();
267267

268268
const invalidInputGroups = fixture.debugElement.nativeElement.querySelectorAll(`.igx-input-group--invalid`);
269-
expect(invalidInputGroups.length).toBe(4);
269+
expect(invalidInputGroups.length).toBe(6);
270270

271271
const requiredInputGroups = fixture.debugElement.nativeElement.querySelectorAll(`.igx-input-group--required`);
272-
expect(requiredInputGroups.length).toBe(4);
272+
expect(requiredInputGroups.length).toBe(6);
273273
});
274274

275275
it('When updating two inputs with same attribute names through ngModel, label should responds', fakeAsync(() => {
@@ -1033,7 +1033,20 @@ class DataBoundDisabledInputWithoutValueComponent extends DataBoundDisabledInput
10331033
<input type="number" formControlName="num" igxInput igxMask="###">
10341034
</igx-input-group>
10351035
</section>
1036-
</form>`
1036+
</form>
1037+
<form>
1038+
<section>
1039+
<igx-input-group>
1040+
<label igxLabel>single line</label>
1041+
<input type="text" [formControl]="inputControl" igxInput>
1042+
</igx-input-group>
1043+
<igx-input-group>
1044+
<label igxLabel>multi line</label>
1045+
<textarea type="text" [formControl]="textareaControl" igxInput></textarea>
1046+
</igx-input-group>
1047+
</section>
1048+
</form>
1049+
`
10371050
})
10381051
class ReactiveFormComponent {
10391052
@ViewChild('strinput', { static: true, read: IgxInputDirective }) public strIgxInput: IgxInputDirective;
@@ -1045,6 +1058,9 @@ class ReactiveFormComponent {
10451058
num: [null, Validators.required]
10461059
});
10471060

1061+
public inputControl = new FormControl('', [Validators.required]);
1062+
public textareaControl = new FormControl('', [Validators.required]);
1063+
10481064
constructor(private fb: UntypedFormBuilder) { }
10491065

10501066
public markAsTouched() {
@@ -1056,6 +1072,12 @@ class ReactiveFormComponent {
10561072
}
10571073
}
10581074
}
1075+
1076+
this.inputControl.markAsTouched();
1077+
this.inputControl.updateValueAndValidity();
1078+
1079+
this.textareaControl.markAsTouched();
1080+
this.textareaControl.updateValueAndValidity();
10591081
}
10601082
}
10611083

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
} from '@angular/core';
1515
import {
1616
AbstractControl,
17-
FormControlName,
1817
NgControl,
1918
NgModel
2019
} from '@angular/forms';
@@ -108,8 +107,8 @@ export class IgxInputDirective implements AfterViewInit, OnDestroy {
108107
@Optional() @Self() @Inject(NgModel) protected ngModel: NgModel,
109108
@Optional()
110109
@Self()
111-
@Inject(FormControlName)
112-
protected formControl: FormControlName,
110+
@Inject(NgControl)
111+
protected formControl: NgControl,
113112
protected element: ElementRef<HTMLInputElement>,
114113
protected cdr: ChangeDetectorRef,
115114
protected renderer: Renderer2

0 commit comments

Comments
 (0)