In this tutorial you will learn how to Use ConfiForms Field Definition Rule to reduce a number of choices in a dropdown field.
We will consider 2 setups - one which uses database and another, which uses other form.
This tutorial is aplicable not only to dropdown fields, but also to:
- radio group fields
- advanced dropdowns
- multi-select fields
- checkbox groups fields
If you are new to ConfiForms, please take a few minutes to read the Basic concepts Guide, or go through the video tutorial on that page.
Let's start with form design. It will have just 2 fields
- a checkbox field called "includeActiveOnly"
- a dropdown field called "choices" with values loaded from
- a database table
- another form
This means that we will have 2 variants of the same form (or 2 forms you may say)
Dropdown choices from a database table
Let's start with the one which has a dropdown field with the values loaded from a database table
A table we connect as a dropdown source has the following structure
This is stored in a table called "cf_demo_values"
Our "choices" dropdown is configured as follows
It uses the SQL to load the values
Important note is that we actually load the values for all 3 columns, while only first 2 columns are used directly when showing the values in the dropdown.
However... we need these values from a 3rd column into our dataset to use then later in a filter (in ConfiForms Field Definition Rule)
When SQL is loaded into ConfiForms the names for columns which have underscore (_) in their names are removed
So, in our case the column "is_active" becomes "isactive"
This is very important when you use it in a filter later, see below
Then form in the view mode looks like this
And this is how it looks in the design mode
Let's see how the 2 last macros (Field Definition Rules) are configured
See an important bit on the filter field - we take only "active" rows. This "isactive" field value comes from an SQL, from a field "is_active"
This rule fires when checkbox is checked
Here is how the 2nd Rule is configured
In a filter we tell it to take ALL (this rule fires when checkbox is not checked)
Dropdown choices from another form
This is a 2 version of the form, when your dropdown field is actually takes the values from another ConfiForms Form (using a "smart" field, a "smart" dropdown)
In the edit mode the form looks exactly the same as in the 1st version.
But the difference is in how the "choices" field is configured
It is configured to take the vlues from another ConfiForms Form with the following structure
- Field to store name (field types is "text")
- Field to store the status (active or inactive), with field type "checkbox"
Same set of values as in the database version
And the "choices" field is configured like this:
Taking the values from a "choiceForm" and showing those in teh dropdown
As we have the same field name to show if the choice is active or not the Field Definition Rules stay the same as in the version 1 of the form.
Giving us the same result in the end
Showing only active choices and serving them from another ConfiForms Form
Complete solution for version 1 of the form