Skip to main content

Overview

The Form component is a powerful, declarative form builder that handles various input types including text fields, document uploads, and CSV processing. It automatically manages file uploads, validation, and submission with built-in error handling.

Basic Usage

Element Types

Text Elements

Text elements support various formats and styling options:

Document Elements

Handle PDF and ZIP file uploads with automatic processing:

CSV Elements

Process CSV files and extract data:

API Reference

FormProps

FormElement[]
required
Array of form elements defining the structure and validation rules.
function
required
Callback function called when form is successfully submitted.

FormElement Types

Common properties shared by all form elements:
string
required
Unique identifier for the form field. Used as the key in the results object.
string
required
Display label for the form field.
string
Optional description text shown below the field.
Text input element with formatting options:
'text'
required
Element type identifier.
'text' | 'currency' | 'percentage'
Input format for automatic formatting and validation.
string
Default value for the text field.
string
Text prefix displayed before the input (e.g., ”$” for currency).
string
Text postfix displayed after the input (e.g., ”%” for percentage).
Document upload element for PDFs and ZIP files:
'document'
required
Element type identifier.
boolean
Allow multiple file uploads. Defaults to false.
CSV file upload element:
'csv'
required
Element type identifier.

Return Data Types

The onSubmit callback receives a results object with the following data types:
string
Text inputs return their string values.
DocumentReturn
Single document uploads return an object with id and fileName.
DocumentReturn[]
Multiple document uploads return an array of document objects.
Record<string, string>[]
CSV uploads return an array of objects, one per row, with column headers as keys.

Supported File Types

Document Upload

  • PDF Files: .pdf documents for medical records, reports, and forms
  • ZIP Archives: .zip files containing multiple documents
  • HTML Files: .html files for web-based documents

CSV Upload

  • CSV Files: .csv files with tabular data (comma-separated values)
  • Text CSV: Plain text files with CSV format

Form Features

Text Input Formatting

  • Currency: Automatically formats numbers with decimal places and $ prefix
  • Percentage: Automatically formats numbers with % postfix
  • Custom Prefixes/Postfixes: Override default formatting with custom text

File Upload Features

  • Drag & Drop: Users can drag files directly onto upload areas
  • Multiple Files: Support for uploading multiple documents when allowMultiple is enabled
  • File Preview: Shows selected file names with remove buttons
  • Upload Progress: Real-time upload status with loading indicators
  • Error Handling: Individual file upload error messages with retry capability

Form Validation

  • Built on react-hook-form with zod schema validation
  • Real-time validation feedback
  • Prevents submission until all uploads complete successfully
  • Form-wide error handling with specific error messages

Advanced Examples

Complex Healthcare Form

Form with Conditional Logic

Error Handling

The Form component includes built-in error handling for file uploads and validation:
Upload Failures: If any file uploads fail, the form will display specific error messages and prevent submission until resolved.
Individual File Errors: Each file upload is handled independently. Failed uploads show specific error messages while successful uploads complete normally.
Form State Management: The form manages its own upload state and prevents submission while files are uploading. Use the loading states to provide user feedback.

Upload Behavior

Asynchronous File Processing

The Form handles file uploads asynchronously:
  1. Form Submission: When submitted, all files are uploaded in parallel
  2. Upload Status: Each file shows individual loading/success/error states
  3. Completion: onSubmit is called only after all uploads complete
  4. Error Handling: If any upload fails, onSubmit receives an empty object {}

Upload Data Flow

Integration with Workflow System

The Form component integrates seamlessly with the SampleHC workflow system:
  • Automatic Upload: Documents are uploaded to the platform and return permanent IDs
  • Progress Tracking: Built-in loading states and progress indicators
  • Error Recovery: Robust error handling with retry mechanisms