Skip to main content
This document provides comprehensive information about all available events in JoyDoc and how to handle them.

Event Overview Table

Event Details

onFocus

  • Triggered when: A field receives focus
  • Purpose: Track field focus events for analytics, validation, or UI updates
Event signature:
Parameters:
  • params: Object containing:
    • sdk: ‘js’
    • v: 1
    • type: ‘fieldPositionFocus’
    • _id: Document ID
    • identifier: Document identifier
    • fileId: File ID
    • pageId: Page ID
    • fieldId: Field ID
    • fieldIdentifier: Field identifier
    • fieldPositionId: Field position ID
    • fieldRowId: Row ID (for table fields)
    • fieldColumnId: Column ID (for table fields)
    • fieldColumnIdentifier: Column identifier (for table fields)
  • e: Native DOM focus event
Example:

onChange

  • Triggered when: Document data changes
  • Purpose: Handle document updates, save changes, or sync with external systems
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
  • Theme changes - Toggle between themes
All these will cause changes to the document data Event signature:
Parameters:
  • changelog: Array of change objects describing what was modified
  • doc: The updated document object
Example:

onBlur

  • Triggered when: A field loses focus
  • Purpose: Track field blur events for validation or cleanup operations
Event signature:
Parameters:
  • params: Object containing:
    • sdk: ‘js’
    • v: 1
    • target: ‘fieldPositionBlur’
    • _id: Document ID
    • identifier: Document identifier
    • fileId: File ID
    • pageId: Page ID
    • fieldId: Field ID
    • fieldIdentifier: Field identifier
    • fieldPositionId: Field position ID
    • fieldRowId: Row ID (for table fields)
    • fieldColumnId: Column ID (for table fields)
    • fieldColumnIdentifier: Column identifier (for table fields)
  • e: Native DOM blur event
Example:

onUploadAsync

  • Triggered when: Images or files are uploaded
  • Purpose: Handle file uploads to external storage or processing services
Event signature:
Parameters:
  • params: Object containing upload context and document information
  • fileUploads: Array of file objects to upload
Return value: Array of file objects with:
  • url: Public URL of uploaded file
  • fileName: Name of the file
  • filePath: Path to the file
Example:

onCaptureAsync

  • Triggered when: Barcode is captured for table barcode cells
  • Purpose: Handle camera capture functionality for barcode fields
Event signature:
Parameters:
  • params: Object containing capture context
Return value: String data of the captured barcode Example:

onFileUploadAsync

  • Triggered when: Images or files are uploaded
  • Purpose: Handle field-specific file uploads with custom logic
Event signature:
Parameters:
  • params: Object containing field information and upload context
  • fileUploads: Array of file objects to upload
Return value: Array of file objects with:
  • url: Public URL of uploaded file
  • fileName: Name of the file
  • filePath: Path to the file
Example:

onFileClick

  • Triggered when: A file in a field is clicked
  • Purpose: Handle file interactions like opening, previewing, or downloading
Event signature:
Parameters:
  • params: Object containing:
    • fileId: File ID
    • pageId: Page ID
    • fieldId: Field ID
    • fieldIdentifier: Field identifier
    • fieldPositionId: Field position ID
  • urlObject: Object containing:
    • url: File URL
    • fileName: File name
    • filePath: File path
Example:

onFileDelete

  • Triggered when: A file in a field is deleted
  • Purpose: Handle file deletion with cleanup or confirmation logic
Event signature:
Parameters:
  • params: Object containing:
    • fileId: File ID
    • pageId: Page ID
    • fieldId: Field ID
    • fieldIdentifier: Field identifier
    • fieldPositionId: Field position ID
  • urlObject: Object containing:
    • url: File URL
    • fileName: File name
    • filePath: File path
Example:

onError

  • Triggered when: Errors occur (schema validation, license validation, etc.)
  • Purpose: Handle and display errors to users
Event signature:
Parameters:
  • error: Object containing error information:
    • For schema validation errors: Validation error details
    • For license errors: { code: 'LICENSE_VALIDATION_ERROR', message: string, type: 'license' }
Example:

Complete Example

Here’s a complete example showing how to use all events:

Best Practices

  1. Async Event Handlers: Always use async/await for upload and capture events
  2. Error Handling: Implement proper error handling in all async event handlers
  3. Loading States: Show loading indicators during file uploads
  4. Validation: Use onBlur for field validation
  5. Analytics: Use onFocus and onChange for user interaction tracking
  6. File Management: Implement proper cleanup in onFileDelete handlers
  7. Performance: Debounce onChange events if needed for frequent updates