Skip to content

Commit

Permalink
fix(Disabled): Mark form as dirty when disabling to ensure the disabl…
Browse files Browse the repository at this point in the history
…ed view is propagated with OnPush strategy
  • Loading branch information
zakhenry authored and maxime1992 committed Nov 21, 2021
1 parent 9162538 commit 7d60d42
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions projects/ngx-sub-form/src/lib/ngx-sub-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ export function createForm<ControlInterface, FormInterface>(
setDisabledState$: setDisabledState$.pipe(
tap((shouldDisable: boolean) => {
shouldDisable ? formGroup.disable({ emitEvent: false }) : formGroup.enable({ emitEvent: false });
// without emitting an event the form is not marked as dirty which can cause issues with the display not updating
// to indicate that form elements are disabled, especially with `changeDetection: ChangeDetectionStrategy.OnPush`
// @related https://github.com/cloudnc/ngx-sub-form/issues/143
markDirty(componentInstance);
}),
),
updateValue$: updateValueAndValidity$.pipe(
Expand Down

0 comments on commit 7d60d42

Please sign in to comment.