Back to Tooljet

Form

docs/versioned_docs/version-2.11.0/widgets/form.md

3.20.154-lts18.8 KB
Original Source

Form component can be used to get input from the user and store it in the connected datasource. Form component serves as a parent widget that can store different widgets like texts, input box, dropdown to allow selection, and a button for triggering the event.

<div style={{textAlign:'center'}}> </div>

:::caution Restricted components In order to avoid excessively complex situations, certain components, namely Kanban, calendar, modal, container, ListView, Tabs, and Form, are restricted from being placed within the Form component using drag-and-drop functionality.

If the builder attempts to add any of the aforementioned components inside the Form, an error message will be displayed:

<Restricted component> cannot be used as a child component within the Form. :::

Properties

PropertiesdescriptionExpected value
Button To Submit FormThe dropdown can be used to select the button that will be used as the submit button for the formAny button that will be added as a child component inside the form component can be selected from the dropdown
Loading stateLoading state can be used to show a spinner as the form content. Loading state is commonly used with isLoading property of the queries to show a loading status while a query is being run.Switch the toggle On or click on fx to programmatically set the value {{true}} or {{false}}
Use Custom SchemaEnabling this property allows you to provide a schema for the Form component in the JSON formatSwitch the toggle On or click on fx to programmatically enable the JSON schema
<div style={{textAlign:'center'}}> </div>

Using Custom Schema

It is mandatory to provide the Form schema in the following format:

js
{{{title:"<FormTitle>", properties: {<ProvideSchemaForComponents>}, submitButton: {<PropertiesOfSubmitButton>}}}}
Keydescription
titleThe title key specifies the title of the form.
propertiesThe properties key holds an object that defines the properties of the components that will be inside the form. The Custom Schema for all the components is available below.
submitButtonThis key key holds an object that defines the properties of the Submit Button of the form.

Submit button schema:

js
submitButton: {
    "value": "Submit",
    "styles": {
      "backgroundColor": "blue",
      "textColor": "white",
      "borderRadius": "40",
      "borderColor": "black",
      "loaderColor": "gray",
      "visibility": true,
      "disabledState": false
    },
<div style={{textAlign:'center'}}> </div>

Custom Schema is available for all the components available under the form category in the components manager:

Datepicker

Properties that can be used in Datepicker schema are:

js
datepicker:{
  type: 'datepicker',
  styles: {
    borderRadius: '',
    disabledState: false,
    visibility: true
  },
  validation: {
    customRule: ''
  },
  defaultValue: '',
  disabledDates: '',
  enableDate: '',
  enableTime: '',
  format: ''
}

Example

js
{{{
         "title":"User registration form",
         "properties":{
            "Select the date":{
               "type":"datepicker"
            }
         },
         "submitButton":{
            "value":"Submit"
         }}}}
<div style={{textAlign:'center'}}> </div>

Number Input

Properties

js
numberinput:{
    type:'number',
    styles: {
        backgroundColor: '#f6f5ff',
        borderRadius: '80',
        textColor: 'red',
        borderColor: 'blue',
        disabled: false,
        visibility: false
        },
    value: 10,
    maxValue: 12,
    minValue: 6,
    placeholder: 'test'
    }

Example

js
{{{title:"User registration form",
         properties:{
            'Select the date':{
               type:"datepicker",
            },
            'Choose the date':{
    type:'number',
    styles: {
        backgroundColor: '#f6f5ff',
        borderRadius: '5',
        textColor: 'red',
        borderColor: 'black',
        disabled: false,
        visibility: false
        },
    value: 50,
    maxValue: 100,
    minValue: 6,
    placeholder: 'Select the quantity'
    }
         },
         "submitButton":{
            "value":"Submit"
         }}}}
<div style={{textAlign:'center'}}> </div>

Password

Properties

js
password:{
   type:"password",
   style:{
      "backgroundColor":"green",
      "borderRadius":"60",
      "disabled":false,
      "visibility":true
   },
   validation:{
      customRule:"",
      maxLength:"",
      minLength:"",
      regex:""
   },
   placeholder:"enter a password"
}

Example

js
"Enter the Password":{
               "type":"password",
               "styles":{
                  "backgroundColor":"white",
                  "borderRadius":"5",
                  "disabled":false,
                  "visibility":true
               },
               "placeholder":"enter a password"
            }
<div style={{textAlign:'center'}}> </div>

Checkbox

Properties

js
checkbox:{
  type: 'checkbox',
  styles: {
    checkboxColor: 'red',
    disabled: false,
    textColor: 'red',
    visibility: false
  },
  value: true,
  label: 'TJ checkox'
}

Example

js
"checkbox1":{
   "type":"checkbox",
   "styles":{
      "checkboxColor":"red",
      "disabled":false,
      "textColor":"red",
      "visibility":false
   },
   "value":true,
   "label":"Product 1"
},
"checkbox2":{
   "type":"checkbox",
   "styles":{
      "checkboxColor":"red",
      "disabled":false,
      "textColor":"red",
      "visibility":false
   },
   "value":false,
   "label":"Product 2"
},
"checkbox3":{
   "type":"checkbox",
   "styles":{
      "checkboxColor":"red",
      "disabled":false,
      "textColor":"red",
      "visibility":false
   },
   "value":true,
   "label":"Product 3"
}
<div style={{textAlign:'center'}}> </div>

Toggle

Properties

js
toggle:{
  type: 'toggle',
  styles: {
    textColor: 'red',
    disabled: false,
    visibility: true,
    toggleSwitchColor: 'red'
  },
  value: true,
  label: 'Toggle Switch'
 },

Example

js
{{{title:"User registration form",
         properties:{
         toggle1:{
  type: 'toggle',
  styles: {
    textColor: 'red',
    disabled: false,
    visibility: true,
    toggleSwitchColor: 'red'
  },
  value: true,
  label: 'Enable this option?'
 },
         },
         "submitButton":{
            "value":"Submit"
         }}}}
<div style={{textAlign:'center'}}> </div>

Text Area

Properties

js
textarea:{
  type: 'textarea',
  styles: {
    disabled: false,
    visibility: true,
    borderRadius: 45
  },
  value: 'xyz',
  placeholder: 'Enter text here'
 }

Example

js
Enter the text here':{
  type: 'textarea',
  styles: {
    disabled: false,
    visibility: true,
    borderRadius: 5
  },
  value: 'This is a sample text',
  placeholder: 'Enter text here'
 }
<div style={{textAlign:'center'}}> </div>

Date Range Picker

Properties

js
daterangepicker: {
  type: 'daterangepicker',
  styles: {
    disabled: false,
    visibility: true,
    borderRadius: 100
  },
  defaultEndDate: '12/04/2022',
  defaultStartDate: '1/04/2022',
  format: 'DD/MM/YYYY'
}

Example

js
{{{
         "title":"User registration form",
         "properties":{
         'Select the range': {
  type: 'daterangepicker',
  styles: {
    disabled: false,
    visibility: true,
    borderRadius: 100
  },
  defaultEndDate: '12/04/2022',
  defaultStartDate: '16/01/2020',
  format: 'DD/MM/YYYY'
}
         },
         "submitButton":{
            "value":"Submit"
         }}}}
<div style={{textAlign:'center'}}> </div>

Multiselect

Properties

js
{
  type: 'multiselect',
  styles: {
    disabled: false,
    visibility: true,
    borderRadius: 2
  },
  displayValues: ["one","two","three"],
  label: 'Select options',
  value: [2,3],
  values: [1,2,3],
  showAllOption: false
}

Example

js
'Select an option':{
  type: 'multiselect',
  styles: {
    disabled: false,
    visibility: true,
    borderRadius: 2
  },
  displayValues: ["one","two","three"],
  label: 'Select options',
  value: [2,3],
  values: [1,2,3],
  showAllOption: false
}
<div style={{textAlign:'center'}}> </div>

Star Rating

Properties

js
{
  type: 'starrating',
  styles: {
    disabled: false,
    visibility: true,
    textColor: 'yellow',
    labelColor: 'red'
  },
  allowHalfStar: false,
  defaultSelected: 0,
  label: 'Rate the item',
  maxRating: 6,
  tooltips: ['one'],
}

Example

js
'Select the rating':{
  type: 'starrating',
  styles: {
    disabled: false,
    visibility: true,
    textColor: 'gold',
    labelColor: 'red'
  },
  allowHalfStar: false,
  defaultSelected: 0,
  label: 'Rate the item',
  maxRating: 6,
  tooltips: ['one'],
}
<div style={{textAlign:'center'}}> </div>

File Picker

Properties

js
{
  type: 'filepicker',
  styles: {
    disabled: false,
    visibility: true,
    borderRadius: 10
  },
  enableDropzone: true,
  enableMultiple: true,
  enablePicker: true,
  fileType: '',
  instructionText: 'Select files',
  maxFileCount: 0,
  maxSize: '',
  minSize: '',
  parseContent: false,
  parseFileType: ''
}

Example

js
filepicker1:{
  type: 'filepicker',
  styles: {
    disabled: false,
    visibility: true,
    borderRadius: 10
  },
  enableDropzone: true,
  enableMultiple: true,
  enablePicker: true,
  fileType: '',
  instructionText: 'Select files',
  maxFileCount: 0,
  maxSize: '',
  minSize: '',
  parseContent: false,
  parseFileType: ''
}
<div style={{textAlign:'center'}}> </div>

Text Input

Properties

js
{
    type: 'textinput',
    value: 'Maria',
    placeholder: 'enter first name here',
    label: 'First name',
    validation: {
      maxLength: 6,
      minLength: 2
    },
    styles: {
      backgroundColor: 'red',
      borderRadius: '',
      errorTextColor: '',
      disabled: false,
      visibility: true,
      textColor: 'black'
    },
    },

Example

js
textinput1: {
    type: 'textinput',
    value: 'Maria',
    placeholder: 'enter first name here',
    label: 'First name',
    validation: {
      maxLength: 6,
      minLength: 2
    },
    styles: {
      backgroundColor: 'white',
      borderRadius: '',
      errorTextColor: '',
      disabled: false,
      visibility: true,
      textColor: 'black'
    }
    }
<div style={{textAlign:'center'}}> </div>

Properties

js
{
  type: 'dropdown',
  displayValues: [1, 2, 3],
  values: ['one', 'two', 'three'],
  loading: false,
  value: 2,
  label: 'dropdown test',
  styles: {
    disabled: false,
    visibility: true,
    borderRadius: '',
    justifyContent: 'start'
  }
}

Example

js
dropdown1: 
         {
  type: 'dropdown',
  displayValues: [1, 2, 3],
  values: ['one', 'two', 'three'],
  loading: false,
  value: 2,
  label: 'dropdown test',
  styles: {
    disabled: false,
    visibility: true,
    borderRadius: '',
    justifyContent: 'start'
  }
<div style={{textAlign:'center'}}> </div>

Button

Properties

js
{    type:'button'
    "text": "Submit",
    "styles": {
      "backgroundColor": "blue",
      "textColor": "white",
      "borderRadius": "40",
      "borderColor": "black",
      "loaderColor": "gray",
      "visibility": true,
      "disabledState": false
    },

Example

js
{{{
"title":"User registration form",
         "properties":{
         'Open the page':{
         type:'button',
         value: "Sample text",
         styles:{
      "backgroundColor": "blue",
      "textColor": "white",
      "borderRadius": "40",
      "borderColor": "black",
      "loaderColor": "gray",
      "visibility": true,
      "disabledState": false
    },
    },},
         "submitButton":{
            "value":"Submit"
         }}}}
<div style={{textAlign:'center'}}> </div>

Text

Properties

js
{
  type: 'text',
  value: 'maria',
  styles: {
    backgroundColor: '#f6f5ff',
    textColor: 'black',
    fontSize: '',
    fontWeight: ''
  }
}

Example

js
{{{
"title":"User registration form",
         "properties":{
         text1:{
  type: 'text',
  value: 'This is text component',
  styles: {
    backgroundColor: '#f6f5ff',
    textColor: 'black',
    fontSize: '',
    fontWeight: ''
  },
  },
    },
         "submitButton":{
            "value":"Submit"
         }}}}
<div style={{textAlign:'center'}}> </div>

Radio

Properties

js
radio: {
  type: 'radio',
  styles: {
    textColor: 'black',
    disabled: false,
    visibility: true
  },
  displayValues: ['option 1', 'option 2', 'option 3'],
  label: 'Radio Buttons',
  value: 1,
  values: [1,2,3],
}

Example

js
{{{
"title":"User registration form",
         "properties":{radio: {
  type: 'radio',
  styles: {
    textColor: 'black',
    disabled: false,
    visibility: true
  },
  displayValues: ['option 1', 'option 2', 'option 3'],
  label: 'Radio Buttons',
  value: 1,
  values: [1,2,3],
},},
         "submitButton":{
            "value":"Submit"
         }}}}
<div style={{textAlign:'center'}}> </div>

Events

To add an event to a button group, click on the widget handle to open the widget properties on the right sidebar. Go to the Events section and click on Add handler.

On submit

On submit event is triggered when the button on the form component is clicked. Just like any other event on ToolJet, you can set multiple handlers for on submit event.

On invalid

On invalid event is triggered when the input on the form is invalid.

:::info Check Action Reference docs to get the detailed information about all the Actions. :::

General

Tooltip

A Tooltip is often used to specify extra information about something when the user hovers the mouse pointer over the widget. Under the <b>General</b> accordion, you can set the value in the string format. Now hovering over the widget will display the string as the tooltip.

Layout

LayoutdescriptionExpected value
Show on desktopToggle on or off to display desktop view.You can programmatically determine the value by clicking on Fx to set the value {{true}} or {{false}}
Show on mobileToggle on or off to display mobile view.You can programmatically determine the value by clicking on Fx to set the value {{true}} or {{false}}

Styles

<div style={{textAlign:'center'}}> </div>
StyleDescription
Background colorYou can change the background color of the form by entering the Hex color code or choosing a color of your choice from the color picker.
Border radiusUse this property to modify the border radius of the form component.
Border colorYou can change the color of the border of the form by entering the Hex color code or choosing a color of your choice from the color picker.
VisibilityToggle on or off to control the visibility of the form. You can programmatically change its value by clicking on the Fx button next to it. If {{false}} the widget will not visible after the app is deployed. By default, it's set to {{true}}.
DisableToggle on to lock the widget. You can programmatically change its value by clicking on the Fx button next to it, if set to {{true}}, the widget will be locked and becomes non-functional. By default, its value is set to {{false}}.
Box shadowThis property adds a shadow to the widget.

:::info Any property having Fx button next to its field can be programmatically configured. :::

Exposed Variables

VariablesDescription
dataThis variable holds the data of all the components that are nested inside the form components. You can access the value dynamically using JS: {{components.form1.data.numberinput1.value}}

Component specific actions (CSA)

Following actions of form component can be controlled using the component specific actions(CSA):

ActionsDescription
submitFormYou can submit the form data via a component-specific action within any event handler. Additionally, you have the option to employ a RunJS query to execute component-specific actions such as await components.form1.resetForm()
resetFormYou can reset the form data via a component-specific action within any event handler. Additionally, you have the option to employ a RunJS query to execute component-specific actions such as await components.form1.submitForm()