dynamic-forms / Function

hasFormValue

Generic types:T

Type guard to check if a form event has a form value attached.

Use this to safely access the formValue property on events when withEventFormValue() is enabled globally or options.emitFormValueOnEvents is set to true in the form config.

Presentation

function hasFormValue(event: T): boolean;

Returns

boolean -

true if the event has a form value attached, narrowing the type

Parameters

NameTypeDescription
event
T

The form event to check

Example usage

eventBus.on<SubmitEvent>('submit').subscribe(event => {
  if (hasFormValue(event)) {
    console.log('Form value:', event.formValue);
  }
});