Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit value when writeValue(null|undefined) + defaultValues defined #152

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 8 additions & 2 deletions projects/ngx-sub-form/src/lib/ngx-sub-form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,10 @@ export abstract class NgxSubFormComponent<ControlInterface, FormInterface = Cont
// calling `reset` on a form with `null` throws an error but if nothing is passed
// (undefined) it will reset all the form values to null (as expected)
defaultValues === null ? undefined : defaultValues,
{ emitEvent: false },
// emit to keep internal and external information about data in of control in sync, when
// null/undefined was passed into writeValue
// while internally being replaced with defaultValues
{ emitEvent: isNullOrUndefined(obj) && !isNullOrUndefined(defaultValues) },
);
} else {
const missingKeys: (keyof FormInterface)[] = this.getMissingKeys(transformedValue);
Expand All @@ -269,7 +272,10 @@ export abstract class NgxSubFormComponent<ControlInterface, FormInterface = Cont
const fgDisabled: boolean = this.formGroup.disabled;

this.formGroup.setValue(transformedValue, {
emitEvent: false,
// emit to keep internal and external information about data in of control in sync, when
// null/undefined was passed into writeValue
// while internally being replaced with transformedValue
emitEvent: isNullOrUndefined(obj),
});

if (fgDisabled) {
Expand Down