Rules: Best Practices

Form rules are a great way to add conditional logic into your form. Rules can be used to hide and show different fields or sections of your form on the fly, based on user selection. They can also be used to populate fields with new information, make optional fields required, display messages, and more. When used correctly, rules can become an essential, powerful, tool for helping capture data in a manner that works for your business and use-case. If you are not familiar with how to add rules to your form, please check out this introduction first, and then come back here for some helpful tips.

When used incorrectly, rules can cause unexpected behavior on your form. This article will provide some guidelines for the best way to add rules to your form, and how to avoid making some of the more common mistakes customers might make when setting up a form’s conditional logic.

By following these best practices, you can reduce the complexity of your rules down to the exact logical actions needed for your form. In doing so, you will reduce the chances of encountering some unexpected behavior as a result of rules that are more complex than they need to be. You will also save yourself time in the future if you ever need to add additional fields and logic to your page. With the proper consolidation and grouping of rules, and efficient use of sections, you may not have to edit your rules at all when you add a new field to your form.


When I discuss rules below, I will usually refer to each rule definition by one of its two parts:


Conditions - Conditions are the “IF” part of rule definitions. Each rule definition starts by outlining the conditions that need to be met in order to take a specific action:
If_Condition.png


Actions - Actions are the “THEN” part of rule definitions. This is where you define what actions are taken when a certain condition is met.

Then_Action.png


I am going to show some examples of good and bad rule definitions, which have all been built for an example course signup form.

FormScreenshot.png
When users fill out this form, we need to show fields that are specific to each course. We also need to show a few “General” signup sections where users can submit their contact information. Courses can be taken in-person or online. So, our form needs to show additional fields if our future student wants to take the courses in-person. We need them to specify which location they will visit to take this imaginary course.

Toggling Actions

One of the most common actions used in the rule builder is the Hide/Show action. Based on a given condition, you may want to Hide or Show a section of your form. What you may not know, is that Hide and Show are toggling actions. Toggling actions will take care of both hiding AND showing in one action That means that you do not need to set up your rules like this:

Bad_Hide_Show.png

We can completely remove Rule #2 from this example. Rule #1 will automatically hide and show the “Beginner Course Signup” section for us.

Here is a full list of toggling actions. These actions will toggle on/off based on a single rule definition, and do not require two separate rules for the same field.
Hide/Show
Make Required/Make Not Required
Make Read-Only
Display an Error Message - The error message will go away when the rule’s condition is no longer met

Avoid Duplicates

One of the most common mistakes I see is the duplicate Action. Taking the same action in two different rules can cause your form to behave unexpectedly. As a practice, you should almost never take the same action on the same field in more than one rule.

 

Here is an example of a bad approach to form rules. We are taking the same action on the same fields in two different rules. There is almost always a way to improve rules like this once you have figured out the exact conditions that govern a field.

Bad_Rule_Grouping.png

Check out our next best-practice to see what the correct version of this rule would be.

Group Rules Together Whenever Possible

To save yourself time when defining rules, make sure to group as many conditions and actions together as you can. You want to make sure you minimize the number of rule definitions you create, and group as many actions under the same condition as you can. Our last example had us using a rule to Show new sections after the user has selected which course they want to take. The problem is, many of the actions were duplicates. The only actions I should take in my course-specific rules, should be revealing course-specific parts of the form. I want to create a single rule that Shows all of the “General” sections in one series of actions.

Good_Rule_Grouping.png

Look at how much cleaner that is compared to our last example! Now, as long as the user has picked anything in our “Select a course” dropdown, we will reveal all of the “General” sections on the form. Depending on which course they have selected, we reveal that course’s section in a separate rule.  

Use Form Sections to Save Time

In many cases, you will need to show a group of fields at the same time when some condition is met.You could set up a rule with ten different actions, each action hiding or showing a single field. Or, you can add a section to your form and hide/show that section instead! When you hide or show a section, all fields inside that section will be hidden or shown at the same time.

Not only will this make setting up your rules easier, but it will also save you time in the future. If you add a new field to an existing section, you may not need to add any additional rules for that field. Instead, the existing hide/show rule for the section will be applied to your new field.

Execution Order Matters

The last subject I want to cover is rule execution order. This will rarely be something you need to worry about if you follow the other best practices outlined in this article. However, in situations where you have multiple rules acting on the same field, or a series of rules that take actions on a field AND evaluate the value of that same field, you will need to keep execution order in mind. Additionally, it is very common for users to include this little piece of code in their custom javascript:

function FF_OnAfterRender() {
    FFEvaluateRules();
}

 


Including this in the “Custom Javascript” section of your form settings will guarantee that all of your rules are evaluated when the form loads. This can be useful for getting your form into a certain state before allowing any input on the form.

In the above scenarios, it is important to keep in mind the order in which rules will execute. Execution order is very simple. Rules will execute in numeric order from Rule #1 to your final rule. So, if you do find yourself in a situation where you need to Hide/Show the same field in two different rule definitions, you should know that the last rule that Hides/Shows a field will have the final say on whether or not that field is visible. This is why, in general, you don’t want to put yourself in a situation where execution order matters. Try to build out your form using the best practices outlined above, and think about whether you really need more than one rule definition for the same field action. Most of the time, with proper logic, and efficient rule definitions, you will not.

Was this article helpful?
4 out of 5 found this helpful

Comments

0 comments

Article is closed for comments.