Skip to content

Commit

Permalink
disabled attribute not working (consistently) (#121)
Browse files Browse the repository at this point in the history
disabled attribute not working (consistently)
  • Loading branch information
zak-cloudnc authored Dec 18, 2019
2 parents e01e19a + 79d0e89 commit bdcc5aa
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions projects/ngx-sub-form/src/lib/ngx-sub-form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,25 @@ export abstract class NgxSubFormComponent<ControlInterface, FormInterface = Cont

this.handleFormArrayControls(transformedValue);

// The next few lines are weird but it's as workaround.
// There are some shady behavior with the disabled state
// of a form. Apparently, using `setValue` on a disabled
// form does re-enable it *sometimes*, not always.
// related issues:
// https://github.com/angular/angular/issues/31506
// https://github.com/angular/angular/issues/22556
// but if you display `this.formGroup.disabled`
// before and after the `setValue` is called, it's the same
// result which is even weirder
const fgDisabled: boolean = this.formGroup.disabled;

this.formGroup.setValue(transformedValue, {
emitEvent: false,
});

if (fgDisabled) {
this.formGroup.disable();
}
}

this.formGroup.markAsPristine();
Expand Down

0 comments on commit bdcc5aa

Please sign in to comment.