Skip to content

Commit 5344c3c

Browse files
authored
Merge pull request #10031 from IgniteUI/PMiteva/input-group-reactive
Setting input disabled state in reactive form
2 parents a198cba + a17b406 commit 5344c3c

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,11 +521,16 @@ describe('IgxInput', () => {
521521
fixture.detectChanges();
522522
const igxInput = fixture.componentInstance.strIgxInput;
523523

524+
expect(igxInput.disabled).toBe(false);
525+
expect(igxInput.inputGroup.disabled).toBe(false);
526+
524527
fixture.componentInstance.form.disable();
525528
expect(igxInput.disabled).toBe(true);
529+
expect(igxInput.inputGroup.disabled).toBe(true);
526530

527531
fixture.componentInstance.form.get('str').enable();
528532
expect(igxInput.disabled).toBe(false);
533+
expect(igxInput.inputGroup.disabled).toBe(false);
529534
}));
530535

531536
it('should style input when required is toggled dynamically.', () => {

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,6 @@ export class IgxInputDirective implements AfterViewInit, OnDestroy {
174174
* ```
175175
*/
176176
public get disabled() {
177-
if (this.ngControl && this.ngControl.disabled !== null) {
178-
return this.ngControl.disabled;
179-
}
180177
return this._disabled;
181178
}
182179

@@ -268,6 +265,10 @@ export class IgxInputDirective implements AfterViewInit, OnDestroy {
268265
this.inputGroup.hasPlaceholder = this.nativeElement.hasAttribute(
269266
'placeholder'
270267
);
268+
269+
if (this.ngControl && this.ngControl.disabled !== null) {
270+
this.disabled = this.ngControl.disabled;
271+
}
271272
this.inputGroup.disabled =
272273
this.inputGroup.disabled ||
273274
this.nativeElement.hasAttribute('disabled');
@@ -352,8 +353,8 @@ export class IgxInputDirective implements AfterViewInit, OnDestroy {
352353
if (!this.disabled && (this.ngControl.control.touched || this.ngControl.control.dirty)) {
353354
// the control is not disabled and is touched or dirty
354355
this._valid = this.ngControl.invalid ?
355-
IgxInputState.INVALID : this.focused ? IgxInputState.VALID :
356-
IgxInputState.INITIAL;
356+
IgxInputState.INVALID : this.focused ? IgxInputState.VALID :
357+
IgxInputState.INITIAL;
357358
} else {
358359
// if control is untouched, pristine, or disabled its state is initial. This is when user did not interact
359360
// with the input or when form/control is reset
@@ -459,8 +460,8 @@ export class IgxInputDirective implements AfterViewInit, OnDestroy {
459460
private checkNativeValidity() {
460461
if (!this.disabled && this._hasValidators()) {
461462
this._valid = this.nativeElement.checkValidity() ?
462-
this.focused ? IgxInputState.VALID : IgxInputState.INITIAL :
463-
IgxInputState.INVALID;
463+
this.focused ? IgxInputState.VALID : IgxInputState.INITIAL :
464+
IgxInputState.INVALID;
464465
}
465466
}
466467

0 commit comments

Comments
 (0)