FormSchema API

Complete reference for FormSchema structure, field definitions, and configuration options.

FormSchema Interface

The main schema object that defines your form structure.

PropertyTypeRequiredDescription
idstringYesUnique identifier for the form
titlestringYesForm title displayed to users
descriptionstringNoOptional form description
fieldsFieldDefinition[]YesArray of field definitions
settingsFormSettingsNoForm-level configuration
versionstringNoSchema version for tracking
createdAtDateNoCreation timestamp
updatedAtDateNoLast update timestamp

FormSettings Interface

Optional settings to customize form behavior and appearance.

PropertyTypeDefaultDescription
submitButtonTextstring"Submit"Text for submit button
cancelButtonTextstring"Cancel"Text for cancel button
showLabelsbooleantrueShow field labels
labelPosition'top' | 'left' | 'right''top'Label position relative to field
theme'light' | 'dark''light'Form theme
clearOnSubmitbooleanfalseClear form after submission

FieldValidation Interface

Validation rules applicable to form fields.

PropertyTypeDescription
requiredbooleanField must have a value
minLengthnumberMinimum string length
maxLengthnumberMaximum string length
minnumberMinimum numeric value
maxnumberMaximum numeric value
patternstringRegex pattern for validation
customMessagestringCustom error message

FieldConditions Interface

Conditional logic for showing/hiding fields dynamically.

tsx
interface FieldConditions {
  show?: ConditionRule[];  // Show field when conditions are met
  hide?: ConditionRule[];  // Hide field when conditions are met
  logic?: 'and' | 'or';    // How to combine multiple conditions (default: 'and')
}

interface ConditionRule {
  fieldId: string;              // The field to check
  operator: ConditionOperator;  // Comparison operator
  value?: any;                  // Value to compare against
}

type ConditionOperator =
  // Boolean operators
  | 'is_checked'
  | 'is_not_checked'
  // Comparison operators
  | 'equals'
  | 'not_equals'
  | 'contains'
  | 'not_contains'
  | 'starts_with'
  | 'ends_with'
  | 'is_empty'
  | 'is_not_empty'
  // Numeric operators
  | 'greater_than'
  | 'less_than'
  | 'greater_than_or_equal'
  | 'less_than_or_equal'
  // Array operators
  | 'includes'
  | 'not_includes';

Example Usage

tsx
const schema: FormSchema = {
  id: 'user-registration',
  title: 'User Registration',
  description: 'Create your account',
  fields: [
    {
      id: '1',
      type: 'text',
      name: 'username',
      label: 'Username',
      required: true,
      validation: {
        minLength: 3,
        maxLength: 20,
        pattern: '^[a-zA-Z0-9_]+$',
        customMessage: 'Username must be 3-20 alphanumeric characters'
      }
    },
    {
      id: '2',
      type: 'email',
      name: 'email',
      label: 'Email',
      required: true
    },
    {
      id: '3',
      type: 'password',
      name: 'password',
      label: 'Password',
      required: true,
      validation: {
        minLength: 8,
        customMessage: 'Password must be at least 8 characters'
      }
    },
    {
      id: '4',
      type: 'checkbox',
      name: 'subscribe',
      label: 'Subscribe to newsletter'
    },
    {
      id: '5',
      type: 'text',
      name: 'referralCode',
      label: 'Referral Code',
      conditions: {
        show: [
          {
            fieldId: '4',
            operator: 'is_checked'
          }
        ]
      }
    }
  ],
  settings: {
    submitButtonText: 'Create Account',
    cancelButtonText: 'Reset',
    theme: 'light',
    clearOnSubmit: false
  },
  version: '1.0.0'
};

💡 Best Practices

  • • Use unique IDs for all fields to enable proper tracking
  • • Keep field names consistent with your backend API
  • • Provide clear validation messages to guide users
  • • Use conditional logic sparingly to avoid complexity
  • • Version your schemas for easier tracking and migrations