Implementing a Custom Form Field
Authors:
Cameron Johns, Cille Schliebitz, Anita Gu
Changed on:
3 Feb 2025
Overview
This lesson walks through the implementation of a custom form field component for a Stock Reservation user action. We'll build a field that captures
`locationRef`
`quantity`
`FormFieldProps`
Key points
- User Action Configuration: Enabling user actions in the manifest is a prerequisite for testing the custom field.
- Data Structure: The custom field will capture data in a specific JSON format: { "locationRef": "F_NSYD", "quantity": 1 }.
`StockReservation`
- React Function Component: The custom field is implemented as a React Function Component (FC).
- Interface: The component uses the
`FormFieldProps`
interface from the UX Framework, typed with the output payload structure.`FormFieldProps`
- Handler: The
`onChange`
property of`onChange`
is used to capture user input.`FormFieldProps`
- Field Registration: The custom field is registered with the using a specific name.
`FieldRegistry`
- Workflow Update: The workflow user action definition is updated to use the new custom field type.
- Testing: The lesson includes steps to verify that the custom field is correctly rendered in the user action form.
In this lesson, you will implement a new custom field component for a Stock Reservation user action.
The Ruleset expects an Event Attribute named "
`stockReservation`
`locationRef`
`quantity. `
`{`
` "locationRef": "F_NSYD",`
` "quantity": 1`
`}`
You will build a field to produce this value for the "
`stockReservation`
To start with, let's simply create a "Hello Field" example:
Before you begin creating your field, let's make sure the User Action button is working on the page. Since you are building upon the screen created in the UX Framework course, it is likely that this User Action is not yet configured to show in the Manifest.
Modify the fragment manifest, and enable User Actions by adding the
`actions`
`props`
`"props": {`
` "title": "Product Availability",`
` "actions": {`
` "enabled": true`
` }`
`}`
Check that you now see a "RESERVE" button on the top right of the Availability Screen, as per the video below.
The video below shows how the initial user action is configured and the reservationDetails attribute is typed as "STRING".
- Create a new and define the interface for the outgoing payload. [0:50]
`StockReservation.tsx`
- You now need to define the Field component by once again using the (FunctionComponent) component from React as the base, and typing it to the UX Framework
`FC`
— which in turn requires another generic for the output, in our case we will define it to be our payload structure`FormFieldProps`
. [1:43]`StockReservationPayload`
- The FormFieldProps provides a number of useful properties — use the since this will allow us to capture the user input. [2:36]
`onChange`
- Before you go implement the full function of the component, let's make sure it renders to screen by simply returning a "Hello Form" div. [3:01]
- Register the field with the , and take note of the name. This will be used to configure the workflow later. [3:29]
`FieldRegistry`
- Make sure the local references include a dot slash: [4:02]
`'./fields/StockReservation';`
- Update the workflow user action definition to change the type from to
`STRING`
. [4:13]`stockReservation`

Once complete, open the user action form, and you should see the "Hello Form" text, indicating that the UX Framework has successfully mapped your custom field component to the attribute type defined in the workflow.
Hello Field
This video explains how to create a custom field