onAction()

This event handler runs when any form action is triggered.

Overview

onAction is a <Feathery.Form> prop and callback function to access and modify form state when actions attached to an element like a button or container are triggered, usually via a click. This handler will run twice, once before the element actions are run and once after the element actions are run.

Default form validation logic, if toggled, will run before either case. If an error is detected, onAction will not run until the field error is fixed and the element is clicked again. This function can be asynchronous.

Usage

You can use onAction to short-circuit actions, render a custom component, set field values, and more. The function takes a single Context object that provides form-related state and handlers.

import { init, Form } from '@feathery/react';

function App() {
  // Initialize Feathery
  init('SDKKey', 'bob@feathery.io');

  // Show the `aBcDeF` Feathery form
  return <Form
    formId='aBcDeF'
    // Route to a specific step
    onAction={(context) => {
      context.goToStep("Custom Step");
    }}
  />
}

Context API

triggerData Definition

Return value

A promise can be optionally returned from this function if it's asynchronous and you want execution to await.

Last updated