How To Use Smartforms To Show/Hide Fields Follow
Smartforms are rules that we put in place to show or hide different fields based on the selections of the customer. In most circumstances, this is used to show a field that the user might not otherwise need to see.
Example Smartform: Cardstock vs. Paper
Let's say you use an Advanced Autofill Menu field that allows customers to choose between Cardstock or Paper. Instead of having both the Cardstock color and Paper color fields display at the same time, you can use SmartForms rules to hide one or the other based on the paper type your customer selects. For example, if they select Cardstock, the cardstock colors field display. If they choose Paper, the Paper colors field displays instead. You could set the menu's values like this:
The Smartform rule would look like this:
Creating Your First Smartform Rule
To create a Smartform rule, you will first need to add the following:
1. Trigger Field.
A trigger field is one that acts as a switch. When your customer uses the trigger field, other fields on the order form will be displayed (or hidden). The Paper or Cardstock field from our example above would be our Trigger Field. The following can be used as a trigger field:
- Advanced AutoFill Checkbox
- A checkbox field that has the added ability to fill in other fields if the user selects it
- Advanced AutoFill Menu
- A menu field that has the added ability to fill in other fields based on the selection of the user
- Number
- A simple field that allows to user to enter only numbers. You can also specify a range that they can choose from.
- QwikPrice Formula
- This type of field allows you to create formulas that test the values of the other fields. This is mostly used to calculate a price based on the quantity the user selects.
- QwikVue
- A menu field that displays an image that correlates to the selection. A common example is showing a visual representation of how a paper will be folded.
- DocMart quantity.
- The quantity box for a DocMart Menu or DocMart Single Item can also be used as a trigger
- Checkbox
- A simple checkbox field
- Menu
- A simple menu of options to choose from
- Multi-Select Menu
- A simple field that allows multiple selections from the list
- Radio Buttons
- A simple field that allows for a selection
2. Values of the Trigger Field.
The Values of the Trigger Field refers to the value we assign each selection. From the Form Builder, you will edit the Trigger Field. At the end of each option, we will add @= followed by a number. The easiest method is to go sequentially, starting at 0. Again, using our example above, we would have something that looks like the following:
This allows us to add a rule that states if this field is equal to 1 then show ___ field.
3. Field Groups.
The field groups are the fields that we are showing and hiding based on the rules we are creating. In our example, we have two fields in our Field Groups. The Cardstock Colors menu and Paper Colors menu are only shown once the customer selects which one they would like.
After we create the following fields and add our values, we can create the Smartform rule. To do this, select the Smartforms button from the menu above. From here we can select our Trigger Field, select a value, the fields that will be affected, and whether they will be shown or hidden.
Note: When you create a rule, the opposite rule is automatically created. For example, if you have a field show when a field is 1, then the rule also states that when the field does not equal 1, then hide the field.
After that, you should have a functioning Smartforms rule! Test it out and make sure it works properly.
Tips and Tricks for Smartforms
- Edit Rule.
After creating a SmartForms rule, you can change any part of it by clicking the Edit checkbox. - Delete Rule.
To delete a rule, click the trash can. - Add Rule.
To add a new rule, select a trigger field, value, action, field group, and click the Add Rule button. The Rule making area defaults to =0 then Hide, but this can be changed as needed. - Deleting Fields from an Order Form. If you delete a field from the order form, it will also be deleted from any SmartForms rule it may belong to.
- Deleting Trigger Fields from an Order Form. If you delete a trigger field from the order form, its SmartForms rule will also be deleted.
- Multiple Trigger Fields. A trigger field can be used to create more than one rule. However, care must be used not to create conflicts (See Rule Conflicts).
- Trigger Indicator. Any field on the order form that is being used as a trigger will have a () SmartForms icon located next to the field's udf_FieldName.
Avoid Donut Hole Rules
Occasionally we get a report that a particular SmartForms rule is not working when the value is 0. When we look at the formula, we may find a donut hole rule to be the cause. A show when > 0 rule also implies and does the opposite hide when < 0. Notice that this rule only covers greater than zero and less than zero. It creates a donut hole - it does not cover a situation when the value IS zero! So a rule show when > 0 also means do nothing when =0. To avoid this donut hole problem, use hide <= 0 which implies show when > 0. It's a subtlety that can make a big difference. Everyone likes donuts, but they should be avoided in SmartForms rules.
Rule Conflicts
Twins. It is possible to have two different triggers controlling the same field in the same way. For example, let's say you have two different trigger fields that will each show the same Notes field when either trigger is used and hide it when either trigger is not used. In other words, both trigger fields use 0=Hide. It this case, whichever of the two trigger fields is used last wins any argument.
Solution. It is possible to get around the Opposites rule conflicts using a simple qwikprice formula. For this, you will need to add a Qwikprice Formula to your form. This formula will act as your trigger to show/hide fields. For example, you have a Folding and Cutting field. If the user selects that they would like Folding or Cutting, a notes field should appear for them to add more detail. You could add a formula that states {udf_Cutting} || {udf_Folding}==1?1:0
This formula states that if cutting or folding is selected, then the Qwikprice formula has a value of 1, and if neither option is selected, the formula has a value of 0. You can use this formula as a Smartform trigger to display or hide a Notes field.
Opposites. In contrast to the above, you could also create a set of rules with the exact opposite commands, with one using 0=Hide and the other 0=Show. In this case, Show will be the default, and then Hide when an item is selected.
Make Trigger Fields Required
In general, you should make the main trigger fields required. This will prevent the customer from placing an order without entering the needed info. Of course, not all trigger fields need to be required.
DocMart Limits
You can use the built-in quantity box for a DocMart Menu or a DocMart Single Item as a trigger. For example, entering a number in the quantity box for a DocMart Menu or DocMart Single Item field can be used as a trigger.
So if someone selects a DocMart item from a list, nothing will be triggered, but if someone enters a number in the item's quantity field, fields can be displayed. It would not matter what item was chosen from the list, only that the DocMart quantity box was not 0.
Showing and Hiding Fields Based on DocMart Menu Selections
You can also use a DocMart menu as a trigger field. For example, you have a DocMart menu that has the user select from a list of brochures. The 3rd Brochure requires the user to fill in some notes. We can utilize Smartforms to show a Notes field when the user selects the 3rd Brochure.
To do this, you will need to add a Qwikprice Formula field to the form and paste the following text into it:
var MyItem=thisForm.invlist_DocMartMenuFieldName.options[thisForm.invlist_DocMartMenuFieldName.selectedIndex].text;
if (MyItem == 'Item #1')
{ 1 }
else if (MyItem == 'Item #2')
{ 2 }
else if (MyItem == 'Item #3')
{ 3 }
else
{ 0 }
The bolded portions of this text must be replaced with information you can find on your form. DocMartMenuFieldName refers to what you named your DocMart menu. Items 1-3 refer to the name of the items in the Menu. Below is a screenshot for your reference of how the above example was set up.
Make sure you mark this Qwikprice Formula as hidden, as you do not want to show this field to the customer.
Once you have fixed the field names in the formula, you can use smart forms to show/hide different fields based on the selection they make. 1 represents the first selection, 2 represents the second, and so on.
You will likely have more than 3 options in your DocMart menu. For this, you just need to add more else if lines to the formula. The Formula must end with else {0} or this will not work.
Advanced AutoFill Checkbox Trigger Fields
The value for any kind of Checkbox should be set to @=0|1 (0=unchecked, 1=checked) Note the | symbol (known as a broken bar or pipe) separating the 0 and 1 is created using Shift-\ (Shift, Backslash) on your keyboard. When applying a smartform rule to this, 0 represents the box is unchecked, whereas 1 represents the box is checked
Rehidden Info Is Deleted
The customer can re-hide just as easily as they can show fields. If they have entered info that subsequently gets rehidden as they backtrack, the info is reset. Using our example above, The user selects that they want Cardstock, and then selects that they would like Orange Cardstock. Maybe they want to see the regular paper colors, so they instead select Paper. They are not satisfied with the paper colors, so they re-select Cardstock. MyOrderDesk will NOT save this information, and they would need to re-select that they would like orange cardstock.
This can be avoided by adding a text field with the field name SFNoReset. If you name the field SFNoReset then when a field is re-hidden, the information is not reset. This will affect the entire form, so you need to be careful when/where this is implemented. This effect is useful if you are planning on temporarily hiding information to save space and that information needs to be kept.
Note: There are other fields you can create with special properties such as SFNoReset. You can find an article going over this here
Deleting Rules vs. Changing Them
Rules you create are editable. You can alter everything or anything about it. So you can either delete an existing rule or change it.
Order of Rules Display
The rules you create are displayed in the rule are in the same order the trigger field displays on the order form itself. The fields in the rule's Group are listed A-Z.