Skip to main content

Key-Value

The KeyValueControl component handles dynamic key-value pairs in a form, using Material-UI's Accordion component for better organization and user experience.

Schema

warning

Warning: Avoid using . (dot) in the name property as it can cause issues with nested field paths in the form state.

[
{
"name": "attributes",
"meta": {
"displayType": "keyvalue",
"displayName": "Attributes",
"htmlProps": {
"allowDynamic": true,
"allowAdd": true
},
"validation": {
"max": 5
},
"readOnly": false,
"children": [
{
"name": "key",
"meta": {
"displayType": "text",
"displayName": "Key",
"validation": {
"required": true
}
}
},
{
"name": "value",
"meta": {
"displayType": "text",
"displayName": "Value",
"validation": {
"required": true
}
}
}
]
}
}
]

Example


Form Data:
{}

props

meta object

The meta object contains properties that define the display characteristics and behavior of the KeyValueControl section.

NameDescriptionType
displayNameThe name to display as the section headerstring
htmlPropsProperties for HTML behavior, like allowDynamic and allowAddobject
childrenArray of child fields contained within the KeyValueControlarray
maxMaximum number of items allowed in the key-value pairsnumber
displayTypeType of the field display, which is "keyvalue" in this casestring
readOnlyA readonly field is not editable and value cannot be changedboolean

Example JSON

Key-Value Control with dynamic items

[
{
"name": "attributes",
"meta": {
"displayType": "keyvalue",
"displayName": "Attributes",
"htmlProps": {
"allowDynamic": true,
"allowAdd": true
},
"validation": {
"max": 5
},
"children": [
{
"name": "key",
"meta": {
"displayType": "text",
"displayName": "Key",
"validation": {
"required": true
}
}
},
{
"name": "value",
"meta": {
"displayType": "text",
"displayName": "Value",
"validation": {
"required": true
}
}
}
]
}
}
]

Key-Value Control with validation

[
{
"name": "attributes",
"meta": {
"displayType": "keyvalue",
"displayName": "Attributes",
"htmlProps": {
"allowDynamic": true,
"allowAdd": true
},
"validation": {
"max": 5
},
"children": [
{
"name": "key",
"meta": {
"displayType": "text",
"displayName": "Key",
"validation": {
"required": true,
"requiredDetail": { "errorMsg": "Key is required" }
}
}
},
{
"name": "value",
"meta": {
"displayType": "text",
"displayName": "Value",
"validation": {
"required": true,
"requiredDetail": { "errorMsg": "Value is required" }
}
}
}
]
}
}
]

KeyValueControl with disabled field

[
{
"name": "attributes",
"meta": {
"displayType": "keyvalue",
"displayName": "Attributes",
"htmlProps": {
"allowDynamic": true,
"allowAdd": true
},
"validation": {
"max": 5
},
"children": [
{
"name": "key",
"meta": {
"displayType": "text",
"displayName": "Key",
"isDisabled": true
}
},
{
"name": "value",
"meta": {
"displayType": "text",
"displayName": "Value",
"isDisabled": true
}
}
]
}
}
]