Dynamic Select Filtering
Last updated
Was this helpful?
Last updated
Was this helpful?
Many users utilize the Select component within their form to reference resource data stored within their project. This has several benefits which we have covered in previous documentation. In addition to data reference, users may also need the ability to dynamically filter a Select dropdown based on the selection of another Select dropdown.
For this demonstration, we will be creating a Vehicle Registration system. It will take into account a vehicle’s year, make, and model where the model field is dynamically updated based on the make vehicle value selection.
Within a project, create your first Resource calledVehicle Make
. This will be the initial resource that will trigger the filtering.
Drag and drop a Text Field
component called Make Resource
. Within the component settings, click the API tab and take note of the Property Name makeResource
.
Click the Use tab of the Resource and create a database by submitting two entries: Ford, Chevy.
After making the submissions, click on the Data tab and ensure you see the submissions within the data table.
Next, create a new Resource called Vehicle Model
.
Add a Select
component called Make Reference and a Text Field
component called Model Resource.
Next, we are going to configure the Select component to reference the Make Resource data we generated in the previous step.
Open the Select
Component settings and click the Data
tab. Set the Data Source Type
to Resource
Set the Resource
dropdown to Make
Resource.
Set the Value Property
field to Make Resource
.
This will ensure the Select component references the Make Resource field data from the Vehicle Make resource.
With our Make reference in place, we can now tie together the Models with their respective Make.
Click the Use
tab for the Vehicle Model Resource.
Click the Make dropdown to select Chevy, and input a Chevy model in the Model Text Field.
Make 3 submissions using the Chevy make. e.g.:
Chevy Camaro, Chevy Equinox, Chevy Silverado
Make 3 submissions using the Ford make e.g.:
Ford Mustang, Ford Escape, Ford F-150
Now that we have our database and references established we need a Form to register our vehicles.
1 Click the Forms tab and create a new Form called Vehicle Registration.
2 Add two Select
Components called Make
and Model
and a Text Field
Component called Year
.
Open the Make
component settings and set the Data Source Type
to Resource
Set the Resource
field to Vehicle Make
Set the Value Property
to Make Resource.
This is the same workflow as the Make
Select Component that we set up in the Model
Resource.
Open the Model
component settings. Similarly, set the Data Source Type
to Resource
Set the Resource
field to Vehicle Model
Set the Value Property
to Model Resource.
If we click Use
for the form in this state, both select dropdowns populate with their respective values. However, the Model
field isn’t filtering against the Make
field, which doesn't help us with the filtering we are trying to achieve.
To fix this, we need to make some configurations to the Model component.
Open the settings for the Model
Select Component. Within the Data tab, scroll down to the Filter Query
field which will handle the logic to remove certain Model values when a Make is selected. Add the following query below which equates the value of the Model Resource Make Reference component against the value of the forms Make
Select Component:
Within the Data settings tab, scroll down to the Refresh Options On
field and select the Make field. This will ensure the Model values update anytime a change is made to the Make field.
Finally, check the Clear Value On Refresh Options
to ensure any set value on the Model field is cleared when a new Make value is selected.
With these changes in place, Use
the Vehicle Registration form and select a Make value. The values within the Model field should reflect Models associated with that Make. Changing the Make field should clear the selected Model value and refresh the options to the new Make Models.