dynamic-forms / Function

createSubmissionHandler

Generic types:TFields

Creates an Observable that handles form submission with optional submission action.

This utility encapsulates the submission handling logic:

  • Listens for submit events from the event bus
  • If a submission.action is configured, wraps it and uses Angular Signal Forms' submit()
  • Handles both Promise and Observable returns from the action
  • Uses switchMap to cancel any in-flight submission when a new one starts

The returned Observable should be subscribed to with takeUntilDestroyed() in the component.

Presentation

function createSubmissionHandler(
  options: SubmissionHandlerOptions<TFields>,
): Observable<unknown>;

Returns

Observable<unknown> -

Observable that processes submissions (emits when submission completes)

Parameters

NameTypeDescription
options
SubmissionHandlerOptions<TFields>

Configuration options for the submission handler

Example usage

// In component constructor
createSubmissionHandler({
  eventBus: this.eventBus,
  configSignal: this.config,
  formSignal: this.form,
})
  .pipe(takeUntilDestroyed())
  .subscribe();