...
Excerpt Include | ||||||
---|---|---|---|---|---|---|
|
Let's start with form design. It will have just 2 fields
...
This means that we will have 2 variants of the same form (or 2 forms you may say)
Let's start with the one which has a dropdown field with the values loaded from a database table
...
Code Block |
---|
create table cf_demo_values (id INTEGER NOT NULL, name CHARACTER(50) NOT NULL, is_active boolean); |
Our "choices" dropdown is configured as follows
It uses the SQL to load the values
Code Block |
---|
select id, name, is_active from cf_demo_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)
Warning |
---|
Important! 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)
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
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
Code Block |
---|
<ac:structured-macro ac:macro-id="29ea6581-a183-4fac-b595-8161170b3d06" ac:name="confiform" ac:schema-version="1">
<ac:parameter ac:name="formName">f</ac:parameter>
<ac:rich-text-body>
<ac:structured-macro ac:macro-id="ec132d3d-37c5-48d8-8a11-afc352b2e01a" ac:name="confiform-entry-register" ac:schema-version="1">
<ac:rich-text-body>
<p> </p>
</ac:rich-text-body>
</ac:structured-macro>
<p>
<ac:structured-macro ac:macro-id="a35a3f59-9af3-4b51-a083-e3666d6e033a" ac:name="confiform-field-definition" ac:schema-version="1">
<ac:parameter ac:name="fieldName">includeActiveOnly</ac:parameter>
<ac:parameter ac:name="fieldLabel">Only active</ac:parameter>
<ac:parameter ac:name="type">checkbox</ac:parameter>
</ac:structured-macro>
</p>
<p>
<ac:structured-macro ac:macro-id="94905715-ee3a-440c-9556-86db790db4a9" ac:name="confiform-field-definition" ac:schema-version="1">
<ac:parameter ac:name="fieldName">choices</ac:parameter>
<ac:parameter ac:name="fieldLabel">Your choice</ac:parameter>
<ac:parameter ac:name="values">select id, name, is_active from cf_demo_values</ac:parameter>
<ac:parameter ac:name="extras">7422036e-9a6f-4455-92d9-7140131fb9da</ac:parameter>
<ac:parameter ac:name="type">dbselect</ac:parameter>
</ac:structured-macro>
</p>
<p>
<ac:structured-macro ac:macro-id="afcef165-b323-4b02-adb0-9cfd00d61da2" ac:name="confiform-field-definition-rules" ac:schema-version="1">
<ac:parameter ac:name="condition">includeActiveOnly:true</ac:parameter>
<ac:parameter ac:name="fieldName">choices</ac:parameter>
<ac:parameter ac:name="values">isactive:true</ac:parameter>
<ac:parameter ac:name="action">Apply Filter on a field</ac:parameter>
<ac:parameter ac:name="actionFieldName">includeActiveOnly</ac:parameter>
</ac:structured-macro>
</p>
<p>
<ac:structured-macro ac:macro-id="310c818c-9460-4d7b-a780-ba66ba4c5dda" ac:name="confiform-field-definition-rules" ac:schema-version="1">
<ac:parameter ac:name="condition">includeActiveOnly:false</ac:parameter>
<ac:parameter ac:name="fieldName">choices</ac:parameter>
<ac:parameter ac:name="values">*</ac:parameter>
<ac:parameter ac:name="action">Apply Filter on a field</ac:parameter>
<ac:parameter ac:name="actionFieldName">includeActiveOnly</ac:parameter>
</ac:structured-macro>
</p>
</ac:rich-text-body>
</ac:structured-macro>
|