<- All posts

How to Build Conditional Logic Forms + 5 Examples

Ronan McQuillan
10 min read Feb 12, 2024

Implementing conditional logic is one of the most common ways to make our form tools more effective. On the one hand, conditionality enhances user experiences. More importantly, though, it helps us to gather the right information - even when this varies from case to case.

Today, we鈥檙e checking out how 黑料正能量 makes building conditional logic forms a breeze.

Specifically, we鈥檙e going to look at how we can build five of the most common use cases for conditional forms using our open-source, low-code platform.

Even better, 黑料正能量 empowers teams to build advanced forms on top of just about any kind of data - whether it鈥檚 an API, RDMBS, NoSQL tool, spreadsheet, or our built-in database. So, we can apply the same principles to an almost limitless range of forms.

Let鈥檚 jump right in.

What are conditional logic forms?

Conditional logic means applying rules to determine how our app behaves. Most conditionality rules follow an 鈥渋f/then鈥 structure. So, if a particular condition is met, then something defined happens.

As you know, today, we鈥檙e specifically interested in how we can apply this principle to forms.

There are two broad types of conditional logic forms we need to consider:

  1. Forms where conditions affect the design and UI.
  2. Forms where conditions affect the functionality.

In other words, we can use conditional logic to control how our form looks - or what happens when users interact with it.

The most common example of conditional forms is what鈥檚 called 鈥渂ranching logic鈥.

Basically, this is when a form displays different fields to a user based on their previous answers.

With most traditional form builder tools, this is the limit of what can be achieved using conditional logic.

With 黑料正能量, we can achieve so much more. You might also like our guide to web application development .

How to build forms with conditional logic

Before we dive into some practical examples, it鈥檚 worth going a bit deeper into the two key elements of a conditional form. That is, the condition itself and what we want our form to do when this is met.

Conditions

Conditions are the 鈥渋f鈥 part of our 鈥渋f/then鈥 statements. In computing terms, this is a statement that we define and then evaluate. If this evaluates to true, then we鈥檒l carry out whichever action we鈥檝e set.

In the case of conditional logic forms, this can be based on a number of different kinds of variables, including:

  • Responses to the form itself.
  • User attributes.
  • Access control rules.
  • Contextual factors.
  • System variables and other more advanced conditions.

We might even build very complex rules based on a combination of these factors.

In 黑料正能量, each form component has its own dedicated configuration section for building conditionality rules.

Conditional Logic Forms

To create a condition, we need three things:

  1. A reference value,
  2. An operator,
  3. A comparison value.

So, we might have an expression along the lines of If X equals Y鈥 or If A is greater than B...

With 黑料正能量, we have two ways of setting reference and comparison values:

  1. Providing static values as regular text expressions.
  2. Creating dynamic values by adding bindable JavaScript or Handlebars expressions.

When we bind values, we can access a range of variables relating to the current user, their device, the environment, user roles, system variables, and values from any data source a particular component is exposed to:

Bindings

We can either use these as they are or within more complex custom expressions.

Outcomes

Outcomes are what we do when our condition evaluates to true. Within 黑料正能量, we have three options here:

  1. Hiding the component,
  2. Displaying the component,
  3. Updating a component setting.

The first two are fairly self-explanatory.

We can use conditionality rules to update any setting that鈥檚 configurable for a particular type of component - including design and functionality.

For example, with individual form fields, we can update their default text or the space they occupy on the screen. For buttons, we can update the actions that are carried out when pressed - or simply update their color.

Within 黑料正能量, we can select from these various options using simple dropdown selectors:

Actions

Building 5 types of conditional forms in 黑料正能量

Now that we鈥檝e seen the basics of how we can build conditional logic forms in 黑料正能量 let鈥檚 apply this to some real-world use cases.

Specifically, we鈥檙e going to focus on five of the most illustrative kinds of conditions we can create.

Join 200,000 teams building workflow apps with 黑料正能量

Here goes!

1. Rules based on other form fields

The type of conditionality you鈥檙e most likely familiar with already involves dynamically displaying certain form fields based on a user鈥檚 other answers.

For example, our form might contain fields that are only applicable in certain situations. If they aren鈥檛 applicable, we want to hide them for the sleekest possible UX.

Let鈥檚 check out an example of how we鈥檇 achieve this in the real world.

We鈥檝e got a form for inputting a new employee鈥檚 information:

Set Conditions

The last two fields are an options picker called Employee Level and a file upload field called Badge Photo. The options for Employee Level are Apprentice, Contractor, Junior, Manager, and Senior.

Let鈥檚 say our internal policy is that we don鈥檛 put photos on apprentice鈥檚 badges since they鈥檙e only temporary employees. So, we want to create some conditional logic to hide the Badge Photo field for apprentices.

We鈥檒l start by selecting this field and opening the bindings drawer:

Conditional Form

Here鈥檚 what this looks like.

Custom Condition

We鈥檒l open the bindings drawer for our reference value:

Binding

We want to build our rule around a user鈥檚 previous answer - so we can find this under Form:

Form Inputs

And we鈥檒l select Employee Level.

Employee Level

Lastly, for our comparison value, we鈥檒l simply enter Apprentice as plain text.

Hide Component

Just like that, we have a dynamic form where the Employee Level will disappear if our new colleague is an apprentice:

Dynamic Form

2. User attribute conditions

Let鈥檚 try something a bit more advanced. Besides branching logic, another key use for conditionality within forms is personalization.

Here鈥檚 the exact same form, except we鈥檝e updated the headline text to 鈥淲elcome!鈥. Ultimately, we鈥檇 like to personalize this message a little bit, but we can obviously only do that if we know the user鈥檚 name.

heading

Otherwise, we鈥檒l want to fall back on this generic default message.

We鈥檝e opened the conditionality editor for our Headline component, this time choosing the 鈥淯pdate Setting鈥 option:

Update Setting

We can then choose which of this component鈥檚 settings our rule will alter. We鈥檝e selected Text:

Text

We want our form to say 鈥淲elcome鈥 followed by the current user鈥檚 first name. So, we鈥檒l open the Current Users options:

Current User

And we鈥檙e selecting firstName:

Conditional Logic Forms

Now, we鈥檝e set our action and our reference value. We still need to add our operator and our comparison value. We want to display this personalized text if we know the current user鈥檚 first name.

In other words, if this field is not null.

So we鈥檒l select {{ Current User.firstName }} as our comparison value, and we鈥檒l use Is Not Empty as our operator:

Operators

And here鈥檚 the result:

Personalized Forms

3. User role conditions

Another use case for conditional logic forms is governing which specific data attributes certain users are allowed to update. In other words, we might have some form fields that we want to reserve for higher access roles.

We鈥檝e added two additional form fields called Start Date and End Date.

Date fields

We always want to display these, but we only want them to be editable by users with an Admin role.

For each of our new fields, we鈥檒l need to start by creating an Update Setting rule again. This time, the setting we鈥檙e choosing is called Disabled, and we鈥檙e updating it to be selected:

img

The reference value is another Current User field called roleId:

RoleID

黑料正能量 has four built-in access roles, each with a name and a corresponding ID. We can access the ID attribute for these under the Role heading in the bindings drawer for our comparison value:

Role

These fields should only be editable for users with an Admin role, so that鈥檚 what we鈥檙e choosing:

Admin

We鈥檙e also choosing Not Equals for our operator:

Not Equals

We have an Admin account on our 黑料正能量 tenant, so these fields still appear as editable for us in the builder:

Conditional Logic Forms

However, when we preview our app as a Basic user, they鈥檒l be disabled:

Preview

4. Contextual conditions

We can also use contextual information to apply conditions to our form UI. We鈥檝e made another modification to our form, this time wrapping the First Name and Last Name fields in a horizontal container so they appear on a single line:

Layout

This is a better UX if we access our form on a desktop, but it doesn鈥檛 work as nicely on mobile:

Mobile

We鈥檙e going to create a condition for our new container that updates its Direction setting to Vertical:

Update Setting

We want to apply this setting when the current user鈥檚 device is a mobile phone. We鈥檝e got a category of helpers called Device:

Mobile

Inside this, we can choose Mobile:

Conditional Logic Forms

This is a contextual boolean variable that evaluates to true when a user accesses our form from a mobile device. So, instead of binding a comparison value, we鈥檒l select Boolean:

Boolean

And lastly, we鈥檒l set our comparison value to True:

True

When we apply this rule, our name fields will be arranged vertically for mobile users:

Mobile UX

5. Advanced conditionality rules

黑料正能量 stands head and shoulders above traditional form builders for creating advanced, custom solutions. With a built-in automation builder, extensive external data support, custom front-end scripting, and more, there鈥檚 huge scope for building complex conditionality rules.

We can connect to just about any API or data source - and use query responses however we want.

This means that we can create conditional logic within our forms that would never be possible in traditional form builders that lack this level of connectivity and data support.

To demonstrate this, we鈥檝e added an API request to our example app.

API Request

You can check out our to learn more about how this works.

Our API request accepts a bindable value to represent an email address and returns a JSON object with a series of key/value pairs relating to the validity of this. We only care about one of these, which is called status.

This can either return 鈥榲alid鈥 or 鈥榠nvalid鈥.

We want to use this information to verify the email address that users submit to our form. We鈥檒l then update its design to reflect this.

Back on the design tab, we can open the On-Change actions drawer for our email field:

On Change Action

As the name suggests, this allows us to define actions that will be carried out each time the field is updated.

We鈥檙e adding an action called Execute Query and setting it to our REST request.

Query

We鈥檒l bind the email parameter for this request to the value that鈥檚 been submitted in the email field of our form:

Binding

Then, we鈥檒l add an Update State action to save the status attribute from our query result.

Update State

We鈥檝e done this with the binding {{ Action 1.Query result.data.0.status }}. So, once an email address has been submitted, our state can either be 鈥渧alid鈥 or 鈥渋nvalid鈥.

We鈥檒l add an Update Setting condition to our email field, which updates the Help Text:

Help Text

We鈥檒l use the 鈥渟tatus鈥 attribute under State to set our new Help Text to:

1Email address is {{ State.status }}

Help Text

Our comparison value is {{ State.status }} and we鈥檙e using an Is Not Empty operator:

State

Now, if we enter an invalid email address, we鈥檒l see a message that reads, 鈥淓mail address is invalid鈥.

Conditional Logic Forms

We鈥檒l also see a corresponding message if we input a valid email address.

Build advanced forms with 黑料正能量

黑料正能量 is the open-source, low-code platform that empowers teams to turn data into action.

Today, we鈥檝e aimed to show off how our platform can be used to build advanced forms on top of just about any data source. Of course, we can鈥檛 show every possible use case for conditional logic forms.

Rather, the idea is to demonstrate the unrivaled flexibility 黑料正能量 offers for building custom solutions at pace.

To learn more, check out our forms page .