Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ export class FormControlDirective extends NgControl implements OnChanges, OnDest
cleanUpControl(previousForm, this, /* validateControlPresenceOnChange */ false);
}
setUpControl(this.form, this);
if (this.control.disabled && this.valueAccessor!.setDisabledState) {
this.valueAccessor!.setDisabledState!(true);
if (this.valueAccessor!.setDisabledState) {
this.valueAccessor!.setDisabledState!(this.control.disabled);
}
this.form.updateValueAndValidity({emitEvent: false});
}
Expand Down
19 changes: 18 additions & 1 deletion packages/forms/test/reactive_integration_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,23 @@ const ValueAccessorB = createControlValueAccessor('[cva-b]');
expect(input.nativeElement.disabled).toBe(false);
});

it('should remove disabled attribute when control is replaced with enabled one', () => {
const fixture = initTest(FormControlComp);
const enabledControl = new FormControl('enabled');
const disabledControl = new FormControl('disabled');
disabledControl.disable();
fixture.componentInstance.control = disabledControl;
fixture.detectChanges();

const input = fixture.debugElement.query(By.css('input'));
expect(input.nativeElement.disabled).toBe(true);

fixture.componentInstance.control = enabledControl;
fixture.detectChanges();

expect(input.nativeElement.disabled).toBe(false);
});

it('should add disabled attribute to child controls when disable() is called on group',
() => {
const fixture = initTest(FormGroupComp);
Expand Down Expand Up @@ -4876,4 +4893,4 @@ class MinMaxFormControlComp {
form!: FormGroup;
min: number|string = 1;
max: number|string = 10;
}
}