Optional FeaturesConditional fields

There are two existing plugins for conditional fields in Dato:

  • Conditional Fields - This is the default plugin and is used for most projects, only supports boolean fields.
  • Dropdown Conditional Fields - This plugins handles a string fields, like a dropdown, and allows for conditional fields based on the value of the dropdown. This plugin is outdated and so there is a third alternative:

Our own “Better Conditional Fields” plugin.

Installing the Better Conditional Fields plugin

The plugin is installed by default in Forge, from Nordstan onwards. The source for the plugin is here. Deployment is handled automatically via the Vercel project.

Configuration

The plugin has a configuration setup for specific fields. Open a string field and go to Presentation, click Insert add-on and select Better Conditional Fields. A JSON editor will show up, where you can configure which options should show which fields. The JSON schema is structured like this:

// Schema
{
  "{{this_field_value}}": [
    "{{other_field_to_show_when_this_field_is_this_value}}",
    "{{other_field_to_show_when_this_field_is_this_value}}",
    "..."
  ]
}
 
// Example configuration
{
  "internal_default": [
    "title",
    "internal_link",
    "params"
  ],
  "internal_index": [
    "title",
    "internal_link",
    "params",
    "link_store_type",
    "link_category",
    "link_tag"
  ],
  "external": [
    "title",
    "external_url"
  ],
  "navigation": [
    "title",
    "external_url",
    "internal_link",
    "child_links",
    "params"
  ]
}