Schema

Form Schema Documentation

MuiForms uses a JSON-based schema format to define form structure, validation rules, dependencies, and layout. This guide explains how to structure schemas to build powerful dynamic forms.

Understanding Schema Structure

A complete MuiForms schema follows this basic structure:

{
  "fields": [
    {
      "name": "fieldName",
      "prop": { /* field grouping */ },
      "meta": { /* field configuration */ }
    }
  ]
}

Schema Anatomy

1. Field Name (name)

  • Required: Yes
  • Type: String
  • Description: Unique identifier for the field used when submitting form data
  • Rules: No spaces, no special characters, must be unique within the form
  • Example: firstName, email_address, contact_phone

2. Field Grouping Property (prop)

  • Required: Optional
  • Type: String
  • Description: Specifies a property key for organizing field data within the form submission payload. When provided, the field value is nested under the specified key in the submitted JSON structure. This enables hierarchical data organization during form submission events such as submit and next actions.
  • Example:
    {
      "name": "firstName",
      "prop": "personalDetails",
      "meta": { /* field configuration */ }
    }
  • Result on Submission: Field value will be nested as { "personalDetails": { "firstName": "value" } }

3. Field Configuration (meta)

  • Required: Yes
  • Type: Object
  • Description: Controls how the field is displayed and behaves

Meta Properties

The meta object defines the field's appearance and functionality:

PropertyTypeRequiredDescription
displayNamestringYesLabel shown to users
displayTypestringYesField control type (text, email, select, checkbox, etc.)
valueanyNoInitial or current field value
typestringNoSpecial type: "section" for grouping, "hidden" for hidden fields
optionsarrayNoAvailable choices for select/radio/checkbox fields
placeholderstringNoHint text inside the field
isDisabledbooleanNoDisables user interaction
isReadonlybooleanNoPrevents editing but shows value
validationobjectNoValidation rules and constraints
dependenciesobjectNoField visibility/data relationships
displayPropsobjectNoResponsive layout configuration
eventsobjectNoCallbacks for field changes

Validation Properties

Define validation rules in the validation object:

{
  "meta": {
    "validation": {
      "required": true,
      "pattern": "^[a-zA-Z]+$",
      "min": 3,
      "max": 50,
      "minLength": 3,
      "maxLength": 50
    }
  }
}
PropertyTypeField TypesPurpose
requiredbooleanAllField must be filled
patternregex stringText fieldsMust match regex pattern
minnumberNumber/DateMinimum value
maxnumberNumber/DateMaximum value
minLengthnumberText fieldsMinimum character count
maxLengthnumberText fieldsMaximum character count

More on validation →

Display Props (Responsive Layout)

Control field width across different screen sizes using Bootstrap-style breakpoints:

{
  "meta": {
    "displayProps": {
      "xs": "12",   // Extra small: 100% width
      "sm": "12",   // Small: 100% width
      "md": "6",    // Medium: 50% width
      "lg": "4",    // Large: 33% width
      "xl": "3",    // Extra large: 25% width
      "xxl": "2"    // XXL: 16% width
    }
  }
}

Valid values: 1-12 (12 is 100% width)

More on layouting →

Field Dependencies

Create relationships between fields: show/hide, enable/disable, or update based on other field values.

{
  "meta": {
    "dependencies": {
      "exists": {
        "field": "country",
        "operator": "equals",
        "value": "US"
      }
    }
  }
}

Complete dependency guide →

Events

Respond to field changes with callbacks:

{
  "meta": {
    "events": {
      "onChange": "handleFieldChange",
      "onBlur": "handleBlur"
    }
  }
}

More on field events →


Progressive Examples

Example 1: Simple Text Field

The most basic form field:

{
  "fields": [
    {
      "name": "firstName",
      "meta": {
        "displayName": "First Name",
        "displayType": "text",
        "placeholder": "Enter first name"
      }
    }
  ]
}

Example 2: Text Field with Validation

Add validation rules:

{
  "fields": [
    {
      "name": "email",
      "meta": {
        "displayName": "Email Address",
        "displayType": "email",
        "placeholder": "you@example.com",
        "validation": {
          "required": true,
          "pattern": "^[^@]+@[^@]+\\.[^@]+$"
        }
      }
    }
  ]
}

Example 3: Select Field with Options

{
  "fields": [
    {
      "name": "country",
      "meta": {
        "displayName": "Country",
        "displayType": "select",
        "options": [
          { "label": "United States", "value": "US" },
          { "label": "Canada", "value": "CA" },
          { "label": "Mexico", "value": "MX" }
        ],
        "validation": {
          "required": true
        }
      }
    }
  ]
}

Example 4: Select with Remote Options

Load options from an API:

{
  "fields": [
    {
      "name": "state",
      "meta": {
        "displayName": "State",
        "displayType": "select",
        "config": {
          "url": "https://api.example.com/states",
          "queryParams": [
            ["country", { "type": "fieldValue", "ref": "country" }]
          ],
          "labelKey": "name",
          "valueKey": "code"
        }
      }
    }
  ]
}

Example 5: Conditional Field Display

Show field only when condition is met:

{
  "fields": [
    {
      "name": "hasShippingAddress",
      "meta": {
        "displayName": "Different shipping address?",
        "displayType": "checkbox"
      }
    },
    {
      "name": "shippingAddress",
      "meta": {
        "displayName": "Shipping Address",
        "displayType": "text",
        "dependencies": {
          "exists": {
            "field": "hasShippingAddress",
            "operator": "===",
            "value": true
          }
        }
      }
    }
  ]
}

Example 6: Grouped Form (Sections)

Organize related fields into groups:

{
  "fields": [
    {
      "name": "personalInfo",
      "meta": {
        "displayName": "Personal Information",
        "type": "section"
      }
    },
    {
      "name": "firstName",
      "meta": {
        "displayName": "First Name",
        "displayType": "text"
      }
    },
    {
      "name": "lastName",
      "meta": {
        "displayName": "Last Name",
        "displayType": "text"
      }
    },
    {
      "name": "billingInfo",
      "meta": {
        "displayName": "Billing Information",
        "type": "section"
      }
    },
    {
      "name": "cardNumber",
      "meta": {
        "displayName": "Card Number",
        "displayType": "text",
        "validation": {
          "required": true,
          "minLength": 13,
          "maxLength": 19
        }
      }
    }
  ]
}

Example 7: Fully Featured Field

A complex field with all options:

{
  "fields": [
    {
      "name": "department",
      "prop": {
        "value": "engineering"
      },
      "meta": {
        "displayName": "Department",
        "displayType": "select",
        "placeholder": "Select your department",
        "config": {
          "url": "https://api.example.com/departments",
          "lazy": true,
          "labelKey": "name",
          "valueKey": "id"
        },
        "validation": {
          "required": true
        },
        "displayProps": {
          "xs": "12",
          "md": "6",
          "lg": "4"
        },
        "dependencies": {
          "exists": {
            "field": "employeeType",
            "operator": "===",
            "value": "full-time"
          }
        },
        "events": {
          "onChange": "handleDepartmentChange"
        }
      }
    }
  ]
}

Complete Schema Reference

{
$schema
:
"http://json-schema.org/draft-04/schema#"
type
:
"object"
title
:
"MuiForm Schema"
description
:
"JSON schema definition used in MuiForm"
properties
:
{
fields
:
{
type
:
"array"
items
:
[
0
:
{
type
:
"object"
properties
:
{
}
required
:
[
]
}
]
}
}
required
:
[
0
:
"fields"
]
}

Available Field Types

Common displayType values:

TypePurposeExample
textSingle-line text inputName fields
emailEmail input with validationEmail address
numberNumeric inputAge, quantity
passwordMasked text inputPassword field
selectDropdown selectionCountry picker
multi-selectMultiple choice dropdownTags, interests
checkboxTrue/false toggleAgreements
radioSingle choice from optionsYes/No/Maybe
dateDate pickerBirth date
fileFile uploadDocument upload
textareaMulti-line textComments, descriptions
searchSearchable dropdownLocation search

See all field types →


Best Practices

DO:

  • Keep field names simple and lowercase with underscores
  • Always provide displayName for user-facing labels
  • Group related fields into sections
  • Use responsive displayProps for better mobile UX
  • Validate critical fields (email, phone, etc.)
  • Use lazy loading for large option lists

DON'T:

  • Use spaces or special characters in field names
  • Skip validation on important fields
  • Hardcode all options (use APIs for large lists)
  • Duplicate field names

Next Steps

Star us at github

© Copyright 2023 MuiForms