Directus CMS 11: Configuring Cascading/Conditional Dropdowns

Directus 11: Configuring Cascading/Conditional Dropdowns
This guide provides step-by-step instructions to configure cascading dropdowns in Directus version 11. This allows you to filter the options available in one dropdown based on the selection made in another dropdown within the same item form.
We will use the example scenario where you have the following collections and relationships:
properties: Contains details about properties.Has a Many-to-One (M2O) relationship to
countries(field key:country).Has an M2O relationship to
states(field key:state).Has an M2O relationship to
cities(field key:city).
countries: A list of countries.states: A list of states.Has an M2O relationship to
countries(field key:country).
cities: A list of cities.Has an M2O relationship to
states(field key:state).
Goal:
When editing a
propertiesitem, thestatedropdown should only show states belonging to the selectedcountry.When editing a
propertiesitem, thecitydropdown should only show cities belonging to the selectedstate.
Prerequisites:
You are using Directus 11.
You have correctly set up the collections (
properties,countries,states,cities) and the Many-to-One (M2O) relationships described above. Ensure you know the Field Keys (the machine-readable names, not just the display names) for each relationship field.
Step 1: Filter states based on country
Navigate to the
stateField Configuration:Go to Settings in the left-hand navigation menu.
Click on Data Model.
Select the
propertiescollection.In the list of fields, click on the
statefield (your M2O field linking to thestatescollection).
Configure the Interface Filter:
The field's configuration options will appear in the sidebar (usually on the right). Click on the Interface tab.
Ensure a relational interface is selected (e.g., "Select Dropdown").
Scroll down to the Filter setting and click "Add Filter".
Define the Filter Rule using the GUI Builder:
Field Selection (First Dropdown): Select the field within the
statescollection that links it to a country. Based on our example, this would likely be displayed asCountry Idor simplyCountry. Choose the option representing the M2O relationship field fromstatestocountries.Operator (Second Dropdown): Select
Equals(or "Is equal to").Value (Third Input): This is the critical step. Manually type the following directly into the value input box:
{{country}}Replace
countrywith the exact Field Key of the M2O field in yourpropertiescollection that links to thecountriescollection.Do not select from a dropdown here; type the text
{{your_country_field_key}}. Directus 11 interprets this syntax in this context as the value of thecountryfield from thepropertiesitem currently being edited.
Save:
Save the filter rule.
Save the field configuration (checkmark or "Save" button at the top of the sidebar).
Save the overall Data Model changes if prompted.
Step 2: Filter cities based on state
Navigate to the
cityField Configuration:Go back to the field list for the
propertiescollection.Click on the
cityfield (your M2O field linking to thecitiescollection).
Configure the Interface Filter:
Go to the Interface tab in the right sidebar.
Ensure a relational interface is selected.
Scroll down to the Filter setting and click "Add Filter".
Define the Filter Rule using the GUI Builder:
Field Selection (First Dropdown): Select the field within the
citiescollection that links it to a state. Based on our example, this would likely be displayed asState Idor simplyState. Choose the option representing the M2O relationship field fromcitiestostates.Operator (Second Dropdown): Select
Equals(or "Is equal to").Value (Third Input): Manually type the following directly into the value input box:
{{state}}Replace
statewith the exact Field Key of the M2O field in yourpropertiescollection that links to thestatescollection.Again, type the text
{{your_state_field_key}}directly.
Save:
Save the filter rule.
Save the field configuration.
Save the Data Model changes if prompted.
Verification:
Go to the properties collection in the Content module and try creating or editing an item.
The
countrydropdown should show all countries.Select a country.
The
statedropdown should now update to show only the states linked to the selected country.Select a state.
The
citydropdown should now update to show only the cities linked to the selected state.
Key Takeaway:
In Directus 11's GUI Filter Builder for Interface options, use the double curly brace syntax ({{field_key_from_current_item}}) in the Value input field to dynamically reference values from other fields within the item currently being edited.