Skip to content

Commit

Permalink
Merge pull request #209 from cloudnc/fix/double-validation-is-required
Browse files Browse the repository at this point in the history
fix(Root form emission): It is required to double check validation of…
  • Loading branch information
zakhenry committed Mar 17, 2021
2 parents 543357e + 078d9cd commit 412c588
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion projects/ngx-sub-form/src/lib/ngx-sub-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,18 @@ export function createForm<ControlInterface, FormInterface>(
)
: formGroup.valueChanges;

// it might be surprising to see formGroup.valid being checked twice
// here, however this is intentional. The delay(0) allows any sub form
// components to populate values into the form, and it is possible for
// the form to be invalid after this process. In which case we suppress
// outputting an invalid value, and wait for the user to make the value
// become valid.
return formValues$.pipe(
filter(() => formGroup.valid),
delay(0),
filter(formValue => (options.outputFilterPredicate ?? isEqual)(transformedValue, formValue)),
filter(
formValue => formGroup.valid && (options.outputFilterPredicate ?? isEqual)(transformedValue, formValue),
),
options.handleEmissionRate ?? identity,
);
}
Expand Down

0 comments on commit 412c588

Please sign in to comment.