Skip to main content

UI Form schema

NOTE

More information about the forms editor here

The UI Schema plays a crucial role in defining how the form fields are presented and organized within the user interface. It leverages JSON Forms' elements to configure the layout and visual styling of the form, ensuring an intuitive and user-friendly experience.

Here's a simple example to illustrate the concept:

{
"type": "VerticalLayout",
"elements": [
{
"type": "Control",
"scope": "#/properties/name"
},
{
"type": "Control",
"scope": "#/properties/email"
},
{
"type": "Control",
"scope": "#/properties/age"
}
]
}

In this example, we use the "VerticalLayout" element to stack the form fields vertically. Each form field is represented by a "Control" element, and the "scope" property specifies the path to the corresponding field in the JSON Schema. This simple UI Schema configuration results in a user interface where the fields "firstName," "lastName," and "email" are displayed vertically, one below the other.

By utilizing JSON Forms' elements and configuring the UI Schema effectively, you can create visually appealing and logically organized forms that enhance the overall user experience.

UI Components

In the UI Schema, you can utilize various elements to define the layout and appearance of your form. Here are some commonly used UI Schema elements with explanations and short examples to help you understand their purpose and usage

Control


The "Control" element is used to render a form field or control in the UI. It allows users to interact with the form by inputting data or making selections. For example, a text input field, a dropdown menu, or a checkbox can be rendered using the "Control" element.

Example:

Schema
UI Schema
NOTE

The type: control is exclusively utilized within the UI Schema.

{
"type": "control",
"scope": "#/properties/name"
}

Group


The "Group" element creates a container to group related fields together. It helps in organizing and visually separating fields that are part of a common category or section. Fields within a group can be displayed with a title or description, providing context to the user.

Example:

Schema
UI Schema
NOTE

The type: group is exclusively utilized within the UI Schema.

{
"type": "group",
"title": "Personal Information",
"elements": [
{
"type": "control",
"scope": "#/properties/firstName"
},
{
"type": "control",
"scope": "#/properties/lastName"
}
]
}

This UI Schema element provide flexibility in designing the layout and structure of your forms, allowing you to create user-friendly and intuitive interfaces for data entry.

Label


This type is used to create a non-editable text or label element that provides information or context within the form. Labels are typically used to display static text, instructions, or descriptions that help users understand the purpose or expected input of the form.

Example:

Schema
UI Schema
NOTE

The type: label is exclusively utilized within the UI Schema.

...
{
"type": "Label",
"text": "Personal data",
<<options>>
}
...
{
"type": "Label",
"text": "History information",
"options": {
"size": "lb-1"
}
}
...
OptionsDescription
sizeSet the label size. The possible values are (from smallest to largest font size): lb-1, lb-2, lb-3, lb-4, lb-5

VerticalLayout


The "VerticalLayout" element is used to stack form fields vertically in the UI. It arranges the fields in a top-to-bottom manner, creating a vertical flow. This is useful when you want to display a series of related fields in a structured manner.

Example:

Schema
UI Schema
NOTE

The type: VerticalLayout is exclusively utilized within the UI Schema.

{
"type": "VerticalLayout",
"elements": [
{
"type": "control",
"scope": "#/properties/firstName"
},
{
"type": "control",
"scope": "#/properties/lastName"
}
]
}

HorizontalLayout


The "HorizontalLayout" element is used to arrange form fields in a horizontal line. It aligns the fields side by side, allowing them to be displayed horizontally. This is suitable for situations where you want to present fields next to each other, such as in a multi-column form layout.

Example:

Schema
UI Schema
NOTE

The type: HorizontalLayout is exclusively utilized within the UI Schema.

{
"type": "HorizontalLayout",
"elements": [
{
"type": "control",
"scope": "#/properties/email"
},
{
"type": "control",
"scope": "#/properties/phone"
}
]
}

Rules

Rules enable the inclusion of interactive features in a form, such as the ability to hide or disable certain user interface elements based on specific conditions.

These rules can be applied to any element within the user interface schema and are defined using the "rule" property, which follows the format:

"rule": {
"effect": "HIDE" | "SHOW" | "ENABLE" | "DISABLE",
"condition": {
"scope": "<UI Schema scope>",
"schema": JSON Schema
}
}

A rule basically works by first evaluating the condition property and in case it evaluates to true, executing the associated effect.

Rule Effect


The effect property determines what should happen to the attached UI schema element once the condition is met. Current effects include:

  • HIDE: hide the UI schema element
  • SHOW: show the UI schema element
  • DISABLE: disable the UI schema element
  • ENABLE: enable the UI schema element

Rule Condition


The condition object of a rule comprises a scope and a schema property. The schema property adheres to the JSON schema standard, allowing for the utilization of any JSON schema specification within the rule condition. The schema undergoes validation against the data specified in the scope property. When the scope data matches the schema, the rule evaluates to true, triggering the application of the rule effect.

Below a rule example:

Schema
UI Schema
{
"title": "Form",
"description": "A form example",
"type": "object",
"properties": {
"name": {
"type": "string"
},
"education": {
"type": "boolean"
},
"kindOfStudy": {
"type": "string",
"enum": ["Primary School", "High School", "University"]
},
"vegetables": {
"type": "boolean"
},
"kindOfVegetables": {
"type": "string",
"enum": ["All", "Some", "Only potatoes"]
}
}
}
{
"type": "VerticalLayout",
"elements": [
{
"type": "Control",
"label": "Name",
"scope": "#/properties/name"
},
{
"type": "Group",
"elements": [
{
"type": "Control",
"label": "Student?",
"scope": "#/properties/education"
},
{
"type": "Control",
"label": "Education Level",
"scope": "#/properties/kindOfStudy",
"rule": {
"effect": "ENABLE",
"condition": {
"scope": "#/properties/education",
"schema": {
"const": true
}
}
}
}
]
},
{
"type": "Group",
"elements": [
{
"type": "Control",
"label": "Eats vegetables?",
"scope": "#/properties/vegetables"
},
{
"type": "Control",
"label": "Kind of vegetables",
"scope": "#/properties/kindOfVegetables",
"rule": {
"effect": "HIDE",
"condition": {
"scope": "#/properties/vegetables",
"schema": {
"const": false
}
}
}
}
]
}
]
}

This example demonstrates the usage of two rules. The first rule controls the enabling of a control based on the status of the 'Student' checkbox. The second rule manages the visibility of a control depending on the selection of the "Eats vegetables?" checkbox.

Kuflow Logo