It is possible to make a certain text appear based on the answers entered in option fields.
In this article you will learn how to condition a piece of text to more than one answer given in one multiple choice field or several option fields, whether they are multiple choice, single choice or dropdowns:
- First of all, we are going to talk about how to display a text only when all the answers in a set of answers are selected.
- Then, we are going to make a text appear only when one or more of the answers in a set of answers are selected.
- Finally, you will see that both tag configurations can be combined.
In all cases, opening and closing tags will be used. To learn more about tags for option fields, check out this article.
1. Display a text only when all the answers in a set of answers are selected
On some occasions, you may want a text to appear when more than one situation or condition are met at the same time.
Imagine a lease in which each party can only be made up of one person, and this can be natural (a physical person) or legal person (a company). The text that will refer to the parties will need to change based on the type of person of not just one, but both parties.
Suppose we have created a single option field for each part:
- The field tag for Party 1 is {party1} and for Party 2 is {party2}.
- In both cases, for the natural person option we use the tag {naturalPerson} and, for the legal person option, {legalPerson}.
If, for example, both party 1 and party 2 are natural persons, we want this phrase to appear in one part of the document:
All of the undersigned persons are bound by the contract.
In this case, the text to condition is "persons" and the conditions are two:
- In the form it has been indicated that Party 1 is a natural person.
- In the form it has also been indicated that Party 2 is a natural person.
How to set the tags in the template to make this happen?
For the platform to identify these two conditions, as we have anticipated at the beginning of the article, you must use opening and closing tags.
On the one hand, place the opening tag just before the text to be conditioned and it will consist of:
- At the beginning, the symbol "#", which indicates opening.
- The conditions, which contain the field tags and the chosen option tags, separated by an underscore (“_”): “party1_naturalPerson” and “party2_naturalPerson”.
- Between the conditions, a space followed by “&&” and another space: “ && ”. This indicates that both conditions must be met at the same time.
On the other hand, the closing tag must be placed just after the text to condition, only with the closing symbol "/".
Next, you can see the result of this tag combination applied to the example:
All of the undersigned {#party1_naturalPerson && party2_naturalPerson}persons{/} are bound by the contract.
If, when filling in the form, party 1 and party 2 have not been marked as natural persons, the necessary conditions will not be met for the text that the tags comprise to be displayed, so we may want to add an alternative text subject to other conditions:
- If both party 1 and party 2 were legal persons, the conditioned text would be “companies” and the one in the tags of the chosen options, “legalPerson”:
{#party1_legalPerson && party2_legalPerson}companies{/}
We can add this combination of tags to the previous example, so that, if both parties are marked as natural persons, it appears “The undersigned persons are bound by the contract” and, if both parties are legal persons, “The undersigned companies are bound by the contract”:
All of the undersigned {#party1_naturalPerson && party2_naturalPerson}persons{/}{#party1_legalPerson && party2_legalPerson}companies{/} are bound by the contract.
2. Display a text when one or more of the answers in a set of answers are selected
In this section you will learn how to configure the opening and closing tags when we want the appearance of certain information to be conditional on compliance with:
- One or other situation (as long as the options are part of the same single option field or dropdown).
- One or more than one of the situations (when they are part of several fields or a multiple choice field).
Returning to the previous example of the lease, let us imagine that the leased property can be a house, a farm, a parking space or a storage room.
We could create a single choice field with the tag {property} and four options with their respective tags: {house}, {farm}, {parking} and {storage}.
In this case, there are two properties (the house and the farm) and two annexes of a property (the parking space and the storage room). Depending on the chosen answer, there could be two possible sentences on the document, for example:
The property is located on {address}.
The annex of the property is located on {address}.
What would be the tag configuration in the template, in this case?
Note that to make the title or value of the selected option appear appear in the document (for example, "The house"), we can simply use the field tag: {property}
We have two possible pieces of text, each one subject to the choice of one of two possible answers.
Let us start with the "property" version. To indicate to the platform that we want the text "The property is located on" to be conditioned to the selection of "house" or "farm" in the form, we must use the following configuration:
{#property_house || property_farm}The property is located on{/}
Just before the text to be conditioned (“The property is located on”), it is placed the opening tag, which contains:
- At the beginning, the symbol "#", which indicates opening.
- The conditions, which contain the field tags and the chosen option tags, separated by an underscore (“_”): “property_house” and “property_farm”.
- Between the conditions, a space followed by “||” and another space: “ || ”. This indicates that at least one of these options must have been chosen for the condition to be fulfilled (in this case, as it is a single option field, only one option can be chosen).
On the other hand, we will put the closing tag just after the text to condition, only with the closing symbol "/".
By also adding the alternative sentence fragment to condition “The annex of the property is located on” with its corresponding tag configuration to the example in question, the result is as follows:
{#property_house || property_farm}The property is located on{/}{#property_parking || property_storage}The annex of the property is located on{} {address}
3. What about combining the mechanisms of both sections 1 and 2?
In the example of section 1, the possibilities that both parties were natural persons and that both parties were legal persons have been covered.
Following the logic of what you learned in section 1, if we also wanted to cover the possibility that one party was a natural person and the other a legal person, making the conditioned text "parties", we could use the configuration that appears in bold:
All of the undersigned {#party1_naturalPerson && party2_naturalPerson}persons{/}{#party1_legalPerson && party2_legalPerson}companies{/}{#party1_naturalPerson && party2_legalPerson}parties{/}{#party1_legalPerson && party2_naturalPerson}parties{/} are bound by the contract.
In this case, for the same text to be conditioned (“parties”) we would be using two configurations of opening and closing tags.
But, since what we are indicating the platform that we want a text to appear when one of the two combinations of response sets occurs in the form, we can combine it with the mechanism learned in section 2:
All of the undersigned {#party1_naturalPerson && party2_naturalPerson}persons{/}{#party1_legalPerson && party2_legalPerson}companies{/}{#party1_naturalPerson && party2_legalPerson || party1_legalPerson && party2_naturalPerson}parties{/} are bound by the contract.
Remember that, using these tags, you can add as many conditions as necessary. In the same way, you can not only use these tags to refer to single choice fields, but also multiple choice fields and dropdowns.
From the mechanisms explained in this article, you could create a multitude of formulas, such as:
{#field1_optionA && field2_optionB || field1_optionC && field3_optionA}Text for the option A of field 1, selected with the option B of field 2; and/or the option C of field 1, selected with the option A of field 3{/}.