KeyValue
The KeyValue
field makes it easy to edit flat key-value pairs stored in JSON
format in the database.
field :meta, as: :key_value
Options
-> key_label
Default
I18n.translate("avo.key_value_field.key")
Possible values
Any string value.
-> value_label
Default
I18n.translate("avo.key_value_field.value")
Possible values
Any string value.
-> action_text
Default
I18n.translate("avo.key_value_field.add_row")
Possible values
Any string value.
-> delete_text
Default
I18n.translate("avo.key_value_field.delete_row")
Possible values
Any string value.
-> reorder_text
Set a custom label for the tooltip on the reorder by drag-and-drop row button.
Default
I18n.translate("avo.key_value_field.reorder_row")
Possible values
Any string value.
-> disabled
Default
false
Possible values
true
, false
-> disable_editing_keys
Default
false
Possible values
true
, false
-> disable_editing_values
Default
false
Possible values
true
, false
-> disable_adding_rows
-> disable_deleting_rows
Default
false
Possible values
true
, false
Customizing the labels
You can easily customize the labels displayed in the UI by mentioning custom values in key_label
, value_label
, action_text
, and delete_text
properties when defining the field.
field :meta, # The database field ID
as: :key_value, # The field type.
key_label: "Meta key", # Custom value for key header. Defaults to 'Key'.
value_label: "Meta value", # Custom value for value header. Defaults to 'Value'.
action_text: "New item", # Custom value for button to add a row. Defaults to 'Add'.
delete_text: "Remove item" # Custom value for button to delete a row. Defaults to 'Delete'.
Enforce restrictions
You can enforce some restrictions by removing the ability to edit the field's key or value by setting disable_editing_keys
or disable_editing_values
to true
respectively. If disable_editing_keys
is set to true
, be aware that this option will also disable adding rows as well. You can separately remove the ability to add a new row by setting disable_adding_rows
to true
. Deletion of rows can be enforced by setting disable_deleting_rows
to true
.
field :meta, # The database field ID
as: :key_value, # The field type.
disable_editing_keys: false, # Option to disable the ability to edit keys. Implies disabling to add rows. Defaults to false.
disable_editing_values: false, # Option to disable the ability to edit values. Defaults to false.
disable_adding_rows: false, # Option to disable the ability to add rows. Defaults to false.
disable_deleting_rows: false # Option to disable the ability to delete rows. Defaults to false.
Setting disabled: true
enforces all restrictions by disabling editing keys, editing values, adding rows, and deleting rows collectively.
field :meta, # The database field ID
as: :key_value, # The field type.
disabled: true, # Option to disable editing keys, editing values, adding rows, and deleting rows. Defaults to false.
KeyValue
is hidden on the Index
view.