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 @@ -88,9 +88,6 @@ export class FormControlDirective extends NgControl implements OnChanges {
ngOnChanges(changes: SimpleChanges): void {
if (this._isControlChanged(changes)) {
setUpControl(this.form, this);
if (this.control.disabled && this.valueAccessor !.setDisabledState) {
this.valueAccessor !.setDisabledState !(true);
}
this.form.updateValueAndValidity({emitEvent: false});
}
if (isPropertyUpdated(changes, this.viewModel)) {
Expand Down
1 change: 1 addition & 0 deletions packages/forms/src/directives/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export function setUpControl(control: FormControl, dir: NgControl): void {
});

if (dir.valueAccessor !.setDisabledState) {
dir.valueAccessor !.setDisabledState !(control.disabled);
control.registerOnDisabledChange(
(isDisabled: boolean) => { dir.valueAccessor !.setDisabledState !(isDisabled); });
}
Expand Down
31 changes: 31 additions & 0 deletions packages/forms/test/reactive_integration_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,37 @@ export function main() {
expect(inputs[0].nativeElement.disabled).toBe(false);
});

it('should remove disabled attribute when re-instantiated as enabled', () => {
const fixture = initTest(FormControlComp);
const input = fixture.debugElement.query(By.css('input'));

const disabledControl = new FormControl({value: 'some value', disabled: true});
fixture.componentInstance.control = disabledControl;
fixture.detectChanges();
expect(input.nativeElement.disabled).toBe(true);

const enabledControl = new FormControl({value: 'some value', disabled: false});
fixture.componentInstance.control = enabledControl;
fixture.detectChanges();
expect(input.nativeElement.disabled).toBe(false);
});

it('should remove disabled attribute when setControl() is called with enabled control',
() => {
const fixture = initTest(FormGroupComp);
const input = fixture.debugElement.query(By.css('input'));

const disabledControl = new FormControl({value: 'some value', disabled: true});
const form = new FormGroup({'login': disabledControl});
fixture.componentInstance.form = form;
fixture.detectChanges();
expect(input.nativeElement.disabled).toBe(true);

const enabledControl = new FormControl({value: 'some value', disabled: false});
fixture.componentInstance.form.setControl('login', enabledControl);
fixture.detectChanges();
expect(input.nativeElement.disabled).toBe(false);
});

it('should not add disabled attribute to custom controls when disable() is called', () => {
const fixture = initTest(MyInputForm, MyInput);
Expand Down