This article explains how to use form fields, user profile fields or groups with a custom visibility within a group in Word.
Groups can be used to group plain text, form fields, user profile fields, images, tables, etcetera and apply visibility to the selection so it is visible, hidden or deleted when a document is created.
Prerequisites
|
Important
|
Example 1 - And() function form field
Use the And() function to toggle the visibility of a form field within a group.
A Form field with a custom visibility is used inside a Group that also has a custom visibility:
The group binding that is used, is:
{{IfElse(Equals(Form.ShowText, "Yes"), VisibilityType.Visible, VisibilityType.Hidden)}}
.
The form field binding that is used, is:
{{IfElse(Equals(Form.Adjective, "quick"), VisibilityType.Visible, VisibilityType.Hidden)}}
.
A user answers the 'Show text' question with 'No' and the 'Adjective' question with 'quick'.
Because 'Show text' is 'No', this means the group will be hidden. As a result you expect everything (the plain text and the form field) to be hidden. This works correctly when the document is created, but when the document is updated with Update document then the value 'quick' is shown in the document.
To solve this add the (parent) group visibility to the (child) form field binding using the And() function. The modified form field binding is:
{{IfElse(And(Equals(Form.ShowText, "Yes"), Equals(Form.Adjective, "quick")), VisibilityType.Visible, VisibilityType.Hidden)}}
This is the output with 'Show text' is 'No':
Combination 1 | Combination 2 | |
---|---|---|
Input | Form.ShowText = 'No', Form.Adjective = 'quick' |
Form.ShowText = 'No', Form.Adjective = 'slow' |
Output | Hidden text | Hidden text |
This is the output with 'Show text' is 'Yes':
Combination 1 | Combination 2 | |
---|---|---|
Input | Form.ShowText = 'Yes', Form.Adjective = 'quick' |
Form.ShowText = 'Yes', Form.Adjective = 'slow' |
Output | The quick brown fox jumps over the lazy dog. | The brown fox jumps over the lazy dog. |
Important
|
Example 2 - And() function child groups
Use the And() function to toggle the visibility of child groups within a parent group.
A template contains fields with personal information (name, mobile phone number and email address):
TipThe phone icon (☎) is a 'Segoe UI Symbol' font symbol. |
Currently the text is always shown, but the wish is to make the following possible:
- Show or hide all the personal information (when hidden then no text is shown in the document).
- If the personal information is shown, but in the user profile no mobile phone number is filled in, then hide the line containing the mobile phone field, including the 'Mobile phone' label.
- Show or hide the phone icon behind the 'Mobile phone' label.
To create this you need nested Groups.
Important
|
One dropdown will be created to show/hide all the personal information and one checkbox to show/hide the phone icon. Follow the steps below:
- Create a data source named 'YesNo' and add the values 'Yes' and 'No' to the Name column. The result looks like this:
- In Template Designer on the Form tab, click + Add question and create a Dropdown form field with these values. Then click Add to form:
- Type: 'Dropdown'.
- Question title: 'Show personal info'.
- Data source: 'YesNo'.
- Label column: 'Name'.
- Default value: 'Yes'.
-
Click + Add question again and create a Checkbox form field with the values below. Then click Add to form:
- Type: 'Checkbox'.
- Question title: 'Show phone icon'.
- Default value: 'true'.
- Add the first level (parent) Group that will show/hide the complete personal information. To do this, select the complete text (all labels and fields and the paragraph mark (¶) at the end), then on the Template tab click + Add smart field and then Group.
- In the Visibility field select Custom Visibility, then in Visibility expression field type this expression:
{{IfElse(Equals(Form.Show_personal_ info.Name, "Yes"), VisibilityType.Visible, VisibilityType.Hidden)}}
:
-
Click Add to template.
- Add the second level (child) Group that will show/hide the line containing the mobile phone field.
To do this, select the complete line containing the mobile phone field, including the 'Mobile phone ☎' label and the paragraph mark (¶) at the end, then on the Template tab click + Add smart field and then Group.
- In the Visibility field select Custom Visibility, then in Visibility expression field type this expression:
{{IfElse(And(Equals(Form.Show_personal_info.Name, "Yes"), Not(Equals(UserProfile.Mobile, ""))), VisibilityType.Visible, VisibilityType.Hidden)}}
.
Note
-
In this expression you also need to add the first level (parent) Group visibility!
If you would not add the part (Equals(Form.ShowPersonalInfo.Name, "Yes"
), then the visibility for the child group can show unexpected results.
-
In this expression you also need to add the first level (parent) Group visibility!
-
Click Add to template.
- Add the third level (child) Group that will show/hide the phone icon.
To do this, select the mobile phone icon (☎), including the space in front of it, then on the Template tab click + Add smart field and then Group.
- In the Visibility field select Custom Visibility, then in Visibility expression field type this expression:
{{IfElse(And(Equals(Form.Show_personal_info.Name, "Yes"), Not(Equals(UserProfile.Mobile, "")), Form.Show_phone_icon), VisibilityType.Visible, VisibilityType.Hidden)}}
.
Note
-
In this expression you also need to add the first level (parent) and second level (child) Group visibility!
If you would not add these parts then the visibility for the (third level) child group can show unexpected results. -
Also note that
Equals
is not used before and that the text"true"
is not used afterForm.ShowPhoneIcon
. This is because it's a checkbox form field that returns the boolean value 'true' (when it's checked).
-
In this expression you also need to add the first level (parent) and second level (child) Group visibility!
-
Click Add to template.
- In the template the result looks like this:
If the red parent group is hidden then this also hides the green and blue child groups.
Creating a document
When a document is created the composer will show these two questions:
In the document the result looks like this:
Input | Form.Show_personal_info.Name = "Yes", UserProfile.Mobile = "06-12345678", Form.Show_phone_icon = "☑" (true) |
---|---|
Output |
Contact: John Johnson Mobile phone ☎: 06-12345678 Email: john@bcompany.com |
Input | Form.Show_personal_info.Name = "Yes", UserProfile.Mobile = "06-12345678", Form.Show_phone_icon = "☐" (false) |
---|---|
Output |
Contact: John Johnson Mobile phone: 06-12345678 Email: john@bcompany.com |
Input | Form.Show_personal_info.Name = "Yes", UserProfile.Mobile = "", Form.Show_phone_icon = "☑" (true) |
---|---|
Output |
Contact: John Johnson Email: john@bcompany.com |
Input | Form.Show_personal_info.Name = "No", UserProfile.Mobile = "06-12345678", Form.Show_phone_icon = "☑" (true) |
---|---|
Output | Hidden text |
Comments
Article is closed for comments.