Skip to content

JsonSchema in Detail

Low-code form development is all about JSON Schema. Understanding this protocol allows us to develop forms more efficiently and quickly.

Structure

First, we need to understand that JSON Schema is an abstraction of a form.

The outermost layer of JSON represents the overall configuration of the form, and the items field contains the configuration of each form item.

Within items, each form item is represented by its own set of properties, such as label, name, and component.

The component property indicates which component should be used for the form item, and props contains the props passed to that component. Most components are based on the element-plus library, so they support all the props documented in the el documentation.

json
{
  "labelWidth": 150, // Width of the form label
  "labelAlign": "right", // Alignment of the form label
  "size": "default", // Size of the form items
  "items": [
    // Configuration of all form items
    {
      "label": "Username", // Label of the form item
      "component": "input", // Component used for the form item
      "props": {
        // Props passed to the component, supporting all the props of the element-plus component
        "placeholder": "Please enter your username"
      },
      "name": "username" // Unique identifier, i.e., the value key
    },
    {
      "label": "Password",
      "component": "password",
      "props": {
        "placeholder": "Please enter your password"
      },
      "name": "password"
    }
  ]
}

Configuration

After understanding the simple example above, here are all the optional configurations:

Overall Form Configuration

ParameterTypeDefaultDescription
labelWidthnumber150Width of the form label
labelAlign'left' | 'top' | 'right' 'right'Alignment of the form label
size'small' | 'default' | 'large''default'Size of the form items
hideRequiredAsteriskbooleanfalseHide the required asterisk in the form
labelBoldbooleanfalseMake the form label bold
disabledbooleanfalseDisable all form items

Form Item Configuration

ParameterTypeDefaultDescription
labelstring-Label
namestring-Unique identifier, i.e., the value key
componentstring-Component to be used
propsobject{}Props passed to the component, refer to the element-plus documentation for details
requiredbooleanfalseWhether the form item is required
initialValueany-Initial value of the form item
helpstring-Help information for the form item
hiddenbooleanfalseWhether to hide the form item
hideLabelbooleanfalseWhether to hide the label of the form item
rulesFormRule[]-Validation rules for the form item, specific to the Input component
childrenFormItemType[]-Data for nested form items, used for containers, cards, grids, etc.
changeFormChange[]-Configuration for triggering actions when the value of the form item changes
designKeystring-Key used by the form designer, automatically generated