Form Field Component
Purpose
Form Field is a component that wraps a form field and provides a label, description, and error message.
Field Component
Field Component is using Formik for form management. It is a wrapper for Formik's field component. More information about Formik's field component can be found here.
Field Definition
Field definition is used to define the field component. It is used to define the field component in the form.
component: field
name: firstName # component / field name is required
props:
label: First Name # label of the field
type: text # type of the field
Props
label(string): The label of the field. (localized)description(string): The description of the field. (localized)error(string): The error message of the field. (localized)type(string): The type of the field. It acceptstext,number,password,email,checkbox,radio,select,select-async,textarea,date,time,datetime,rangedatetime,url,tel,file,hidden,image,range.placeholder(string): The placeholder of the field.defaultValue(string): The default value of the field.items(array): The items of the field. It is used forradioandselecttypes.options(object): The options of the field. Options for Formik field component.
Yaml Example
component: field
name: firstName
props:
label: First Name
type: text
placeholder: Enter your first name
defaultValue: John
Field Types
The following types are supported:
- text
- number
- password
- checkbox
- radio
- select
- select-async
- textarea
- date
- time
- datetime
- rangedatetime
- url
- tel
- secret
- hidden
- file
- image
- range
Text
The text type is used for single-line text input.
component: field
name: firstName
props:
label: First Name
type: text
placeholder: Enter your first name
Text field with edit action
Text fields support an onEditClick prop that renders an edit icon button. When clicked, it triggers the specified action with the current form values passed as context (including the field's current value).
component: field
name: customerName
props:
label: Customer Name
type: text
onEditClick:
action: openEditDialog
options:
valueFieldName: customerName # includes this field's value explicitly in the action context
Number
The number type is used for input fields that should contain a numeric value.
Options: https://s-yadav.github.io/react-number-format/docs/numeric_format for more details.
component: field
name: age
props:
label: Age
type: number
placeholder: Enter your age
options:
decimalScale: 3
Password
The password type is used for password input fields.
component: field
name: password
props:
label: Password
type: password
placeholder: Enter your password
Email
The email type is used for email input fields.
component: field
name: email
props:
label: Email
type: email
placeholder: Enter your email
Checkbox
The checkbox type is used for checkboxes.
component: field
name: terms
props:
label: Terms
type: checkbox
onChange:
- if: "{{ value }}"
then: # if checked
- setStore:
terms: "T"
else: # if unchecked
- setStore:
terms: "N"
onKeyPress: # on key press event for the field
- if: "{{ eval keyCode === 13 }}"
then: # if enter key is pressed
- consoleLog: "Enter key pressed"
Radio
The radio type is used for radio buttons.
component: field
name: PaymentMethod
props:
label: Payment Method
type: radio
items:
- label: Credit Card
value: creditCard
- label: PayPal
value: payPal
Select
The select type is used for select dropdowns.
component: field
name: country
props:
label: Country
type: select
options:
allowSearch: true
allowClear: true
allowMultiple: true
allowCreate: true
items:
- label: United States
value: us
- label: Canada
value: ca
Select Async
Select with query is used to load options from a GraphQL query.
component: field
name: country
props:
label: Country
type: select-async
options:
valueFieldName: "countryCode" # if name is different than value field
itemLabelTemplate: "{{value}}"
itemValueTemplate: "{{id}}"
searchQuery:
name: getCountries
path: countries
totalCountPath: totalCount
valueQuery:
name: getCountry
path: country
allowSearch: true
allowClear: true
allowMultiple: false
allowCreate: true
queries:
- name: getCountries
query:
command: "query { countries { id name } }"
variables: { search: "{{search}}" }
- name: getCountry
query:
command: "query { country(id: {{id}}) { id name } }"
variables: { id: "{{id}}" }
dropDownToolbar:
- component: button
name: createCountryBtn
props:
label:
en-US: Create Country
icon: plus
options:
variant: primary
onClick:
- dialog:
component: Countries/CreateCountry
onClose:
- selectValue: "{{ result.countryCode }}"
onSelectValue:
- setStore:
selectedCountry: "{{ selectedItem }}"
onCreateValue:
- mutation:
command: "mutation { createCountry(input: { countryCode: '{{ value }}' }) { countryCode } }"
variables: { value: "{{ value }}" }