Skip to main content

Overview

The Joyfill SDK provides comprehensive event handling to track all user interactions and document changes. This guide covers how to listen for and handle various types of form changes.

Basic Change Handling

onChange Event

The primary way to listen for form changes is through the onChange callback:

Changelog Structure

Each changelog contains detailed information about the change:

Event Types

Field Events

Field Updates

Field Creation

Field Deletion

Page Events

Page Creation

Page Updates

Table Row Events

Row Creation

Row Updates

🎯 Advanced Event Handling Guide

Overview

The Joyfill SDK provides comprehensive event handling to track all user interactions and document changes. This guide covers all available event handlers and their corresponding changelog structures for advanced form management.

Event Handler Types

The Joyfill SDK provides the following public event handlers:
  • onFocus - Field focus events
  • onBlur - Field blur events
  • onChange - Document changes (field, fieldposition, page, style changes)
  • onCaptureAsync - Barcode capture events
  • onUploadAsync - File upload events (images)
  • onFileUploadAsync - File upload events
  • onFileClick - File click events
  • onFileDelete - File deletion events

Event Parameters

All event handlers receive structured parameters with the following common properties:

Focus and Blur Events

onFocus

Triggered when a field receives focus. Event Parameters:
  • params (Object): Focus context information
  • event (Event): The DOM focus event (call event.blur() to blur the currently focused field)
Changelog Structure:
Usage Example:

onBlur

Triggered when a field loses focus. Event Parameters:
  • params (Object): Blur context information
  • event (Event): The DOM blur event
Changelog Structure:
Usage Example:

Change Events

onChange

The primary event handler for all document changes. Triggered for:
  • Field changes - Field value or property updates
  • Field position changes - Field position, size, or display changes
  • Page changes - Page creation, updates, or deletion
  • Style changes - Theme and styling modifications
Event Parameters:
  • changelogs (Array): Array of changelog objects describing the changes
  • updatedDoc (Object): The updated document state
Field Change Changelog:
Field Position Change Changelog:
Page Change Changelog:
Style/Theme Change Changelog:
Usage Example:

Capture Events

onCaptureAsync - Barcode Capture

Triggered when barcode capture is initiated (e.g., table barcode cell, barcode field). Function Signature:
Description:
  • Called without any parameters when user clicks the barcode capture button
  • Expected to return a Promise that resolves to the captured barcode value (string)
  • The returned value will be automatically populated into the barcode field
Usage Example:

Upload Events

onUploadAsync

Triggered when file upload is initiated for image fields, both in normal fields and table field cells. Note: This function will be called only when onFileUploadAsync is not passed into JoyDoc. If onFileUploadAsync is present, it will be triggered instead of this. Function Signature:
Parameters:
  • params (Object): Upload context information
  • files (Array<File>): Array of File objects selected by the user
Params Structure: Normal Field Upload:
Table Field Upload:
Files Structure:
Usage Example:

onFileUploadAsync

  • onFileUploadAsync is an async callback in fieldSettings.field that handles file uploads for specific fields. It overrides the global onUploadAsync when provided.
Function Signature:
Parameters:
  • params (Object): Upload context information
  • files (Array<File>): Array of File objects selected by the user
Usage Example:

File Interaction Events

onFileClick

Triggered when a file is clicked or selected in an image field. Function Signature:
Parameters:
  • params (Object): Context information about the file click
  • urlObject (Object): Information about the clicked file
Params Object:
URL Object:
Usage Example:

onFileDelete

Triggered when a file is deleted from an image field. Function Signature:
Parameters:
  • params (Object): Context information about the file deletion
  • urlObject (Object): Information about the file being deleted
Usage Example:

Advanced Change Processing

Filtering Changes by Type

Real-World Examples

Form Validation

Auto-Save

Analytics Tracking

Undo/Redo Functionality

Best Practices

1. Efficient Change Processing

2. Error Handling

Troubleshooting

Common Issues

1. onChange Not Firing

Problem: The onChange callback isn’t being called. Solution: Ensure the callback is properly provided:

2. Event Handlers Not Working

Problem: Event handlers like onFocus, onBlur, etc. are not being triggered. Solution: Check that the handlers are properly defined and passed to JoyDoc:
This comprehensive guide covers all available event handlers in the Joyfill SDK, providing developers with the complete information needed to implement robust form handling and user interaction tracking.