Form Components

Form and Field components for user input

Form Components

Form components handle user input with validation and state binding.

Form

A container for form fields with validation and submission handling.

json
{
  "type": "Form",
  "id": "login-form",
  "fields": [
    {
      "name": "email",
      "fieldType": "text",
      "label": "Email",
      "placeholder": "[email protected]",
      "bindTo": "formData.email",
      "validation": {
        "required": { "message": "Email is required" },
        "email": { "message": "Please enter a valid email" }
      }
    },
    {
      "name": "password",
      "fieldType": "password",
      "label": "Password",
      "bindTo": "formData.password",
      "validation": {
        "required": { "message": "Password is required" },
        "minLength": { "value": 8, "message": "Password must be at least 8 characters" }
      }
    }
  ],
  "events": {
    "on_submit": [
      { "type": "call_api", "api": "auth.login", "args_from_state": ["formData"] }
    ]
  }
}

Properties

PropertyTypeDefaultDescription
idstring-Form identifier (required)
fieldsarray[]Form field definitions
layoutvertical | horizontal | inlineverticalForm layout
submitLabelstringSubmitSubmit button label
cancelLabelstringCancelCancel button label
showResetbooleanfalseShow reset button
classNamestring-CSS classes
eventsobject-Event handlers

Events

EventTriggerPayload
on_submitForm submissionForm values

Examples

Login form:

json
{
  "type": "Card",
  "className": "w-full max-w-md",
  "title": "Sign In",
  "content": {
    "type": "Form",
    "id": "login",
    "fields": [
      {
        "name": "email",
        "fieldType": "email",
        "label": "Email",
        "placeholder": "[email protected]",
        "bindTo": "login.email",
        "validation": {
          "required": { "message": "Email is required" },
          "email": { "message": "Invalid email" }
        }
      },
      {
        "name": "password",
        "fieldType": "password",
        "label": "Password",
        "bindTo": "login.password",
        "validation": {
          "required": { "message": "Password is required" }
        }
      },
      {
        "name": "remember",
        "fieldType": "checkbox",
        "label": "Remember me",
        "bindTo": "login.remember"
      }
    ],
    "submitLabel": "Sign In",
    "events": {
      "on_submit": [
        { "type": "set_loading", "loading": true },
        {
          "type": "call_api",
          "api": "auth.login",
          "body": "{{state.login}}",
          "onSuccess": [
            { "type": "navigate", "to": "/dashboard" }
          ],
          "onError": [
            { "type": "show_toast", "message": "Invalid credentials", "level": "error" }
          ]
        },
        { "type": "set_loading", "loading": false }
      ]
    }
  }
}

Inline search form:

json
{
  "type": "Form",
  "layout": "inline",
  "fields": [
    {
      "name": "query",
      "fieldType": "text",
      "placeholder": "Search...",
      "bindTo": "search.query",
      "className": "w-64"
    },
    {
      "name": "category",
      "fieldType": "select",
      "placeholder": "All categories",
      "bindTo": "search.category",
      "options": [
        { "value": "all", "label": "All" },
        { "value": "docs", "label": "Documents" },
        { "value": "images", "label": "Images" }
      ]
    }
  ],
  "submitLabel": "Search",
  "events": {
    "on_submit": [
      { "type": "call_api", "api": "search", "body": "{{state.search}}" }
    ]
  }
}

Field

Individual form field with various input types.

json
{
  "type": "Field",
  "name": "username",
  "fieldType": "text",
  "label": "Username",
  "placeholder": "Enter username",
  "bindTo": "formData.username"
}

Properties

PropertyTypeDefaultDescription
namestring-Field name (required)
fieldTypestringtextInput type
labelstring-Field label
placeholderstring-Placeholder text
descriptionstring-Helper text below field
bindTostring-State path for binding
defaultValueany-Default value
disabledboolean | stringfalseDisabled state
readOnlybooleanfalseRead-only state
requiredbooleanfalseRequired field
validationobject-Validation rules
optionsarray-Options (for select, radio, checkbox-group)
eventsobject-Event handlers
classNamestring-CSS classes

Field Types

Text Input

json
{
  "type": "Field",
  "name": "name",
  "fieldType": "text",
  "label": "Full Name",
  "placeholder": "John Doe",
  "bindTo": "form.name"
}

Password

json
{
  "type": "Field",
  "name": "password",
  "fieldType": "password",
  "label": "Password",
  "bindTo": "form.password"
}

Email

json
{
  "type": "Field",
  "name": "email",
  "fieldType": "email",
  "label": "Email Address",
  "placeholder": "[email protected]",
  "bindTo": "form.email",
  "validation": {
    "email": { "message": "Invalid email format" }
  }
}

Number

json
{
  "type": "Field",
  "name": "quantity",
  "fieldType": "number",
  "label": "Quantity",
  "bindTo": "form.quantity",
  "defaultValue": 1
}

Textarea

json
{
  "type": "Field",
  "name": "description",
  "fieldType": "textarea",
  "label": "Description",
  "placeholder": "Enter a description...",
  "bindTo": "form.description"
}

Select

json
{
  "type": "Field",
  "name": "category",
  "fieldType": "select",
  "label": "Category",
  "bindTo": "form.category",
  "placeholder": "Select a category",
  "options": [
    { "value": "electronics", "label": "Electronics" },
    { "value": "clothing", "label": "Clothing" },
    { "value": "books", "label": "Books" }
  ]
}

Checkbox

json
{
  "type": "Field",
  "name": "agree",
  "fieldType": "checkbox",
  "label": "I agree to the terms and conditions",
  "bindTo": "form.agree"
}

Radio Group

json
{
  "type": "Field",
  "name": "plan",
  "fieldType": "radio",
  "label": "Select Plan",
  "bindTo": "form.plan",
  "options": [
    { "value": "free", "label": "Free - $0/month" },
    { "value": "pro", "label": "Pro - $10/month" },
    { "value": "enterprise", "label": "Enterprise - $50/month" }
  ]
}

Switch/Toggle

json
{
  "type": "Field",
  "name": "darkMode",
  "fieldType": "switch",
  "label": "Dark Mode",
  "bindTo": "settings.darkMode"
}

Date

json
{
  "type": "Field",
  "name": "startDate",
  "fieldType": "date",
  "label": "Start Date",
  "bindTo": "form.startDate"
}

Events

EventTriggerPayload
on_changeValue changes{ value, name }
on_blurField loses focus{ value, name }
on_focusField gains focus{ name }

Validation Rules

json
{
  "validation": {
    "required": { "message": "This field is required" },
    "minLength": { "value": 3, "message": "Minimum 3 characters" },
    "maxLength": { "value": 100, "message": "Maximum 100 characters" },
    "pattern": { "value": "^[A-Za-z]+$", "message": "Letters only" },
    "email": { "message": "Invalid email format" }
  }
}

Validation Rule Types

RuleParametersDescription
requiredmessageField must have a value
minLengthvalue, messageMinimum string length
maxLengthvalue, messageMaximum string length
patternvalue (regex), messageMust match regex
emailmessageValid email format

Example with Events

json
{
  "type": "Field",
  "name": "search",
  "fieldType": "text",
  "label": "Search",
  "bindTo": "filters.search",
  "events": {
    "on_change": [
      {
        "type": "debounced_action",
        "delayMs": 300,
        "action": {
          "type": "call_api",
          "api": "search",
          "body": { "query": "{{state.filters.search}}" }
        }
      }
    ]
  }
}