Understanding Event Handlers
Event handlers are attributes that you apply to input or output fields to define behavior that should occur when specific events happen. They allow you to:- Bind input field values to output field values
- Update field values based on other field changes
- Trigger custom client-side behavior
- Create dynamic, interactive forms
The BindToOutput Event Handler
The most common event handler isBindToOutputAttribute, which automatically populates an input field with a value from an output field.
Basic Usage
How BindToOutput Works
- Form loads - The form is displayed to the user
- User submits - The form is submitted and processed
- Response is returned - The response contains output fields
- Event handler runs - The
BindToOutputevent handler executes - Input field is updated - The input field
UserIdis populated with the value from the output fieldUserId
Common Use Cases
Scenario 1: Multi-Step Workflow
Scenario 2: Edit Form with Pre-filled Values
- User loads the form with
load-userand enters a User ID - The form returns user data in the response
- The
edit-userform opens (via FormLink or InlineForm) - Input fields are automatically populated from the
load-userresponse usingBindToOutput
Scenario 3: Master-Detail Pattern
Event Handler Properties
TheBindToOutputAttribute has the following properties:
OutputFieldId
Specifies the ID of the output field to bind to:Id
The unique identifier for the event handler (read-only):RunAt
Specifies when the event handler should execute (read-only):Creating Custom Event Handlers
You can create custom event handlers by implementing theIFieldEventHandlerAttribute interface:
Event Handler Application Rules
Event handlers can only be applied to compatible field types:- Input field handlers (like
BindToOutput) can only be applied to input fields - Output field handlers can only be applied to output fields
BindingException:
Complete Example
Here’s a complete example showing a workflow with event handlers:Best Practices
- Use Hidden Fields - When binding IDs or internal values, mark fields as hidden to keep the UI clean
- Consistent Naming - Use the same field names in request and response classes for easier binding
- Return Useful Data - Include relevant data in responses that might be needed by subsequent forms
- Chain Workflows - Use event handlers to create smooth multi-step workflows
- Validate Bound Data - Always validate data received from event handlers, just like user input
Next Steps
Custom Properties
Add custom metadata to forms and fields
Creating Forms
Review form creation basics