About this article
This article will explain 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 etc. and apply visibility to the selection so it is visible, hidden or deleted when a document is created.
|
Prerequisites
|
Examples
Example 1
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 used is:
{{IfElse(Equals(Form.ShowText, "Yes"), VisibilityType.Visible, VisibilityType.Hidden)}}
.
The form field binding 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:
Binding (form field) |
{{IfElse(And(Equals(Form.ShowText, "Yes"), Equals(Form.Adjective, "quick")), VisibilityType.Visible, VisibilityType.Hidden)}} | |
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':
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. |
|
Example 2
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):
|
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.
|
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 aDropdown
form field with these values. Then clickAdd to form
:
- Type: 'Dropdown'.
- Question title: 'Show personal info'.
- Data source: 'YesNo'.
- Label column: 'Name'.
-
Default value: 'Yes'.
-
Click
+ Add question
again and create aCheckbox
form field with the values below. Then clickAdd 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 thenGroup
.
- In the
Visibility
field selectCustom Visibility
, then inVisibility expression
field type this expression:{{IfElse(Equals(Form.ShowPersonalInfo.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 thenGroup
.
- In the
Visibility
field selectCustom Visibility
, then inVisibility expression
field type this expression:{{IfElse(And(Equals(Form.ShowPersonalInfo.Name, "Yes"), Not(Equals(UserProfile.MobilePhone, ""))), VisibilityType.Visible, VisibilityType.Hidden)}}
.
-
Note that 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.
-
Note that 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 thenGroup
.
- In the
Visibility
field selectCustom Visibility
, then inVisibility expression
field type this expression:{{IfElse(And(Equals(Form.ShowPersonalInfo.Name, "Yes"), Not(Equals(UserProfile.MobilePhone, "")), Form.ShowPhoneIcon), VisibilityType.Visible, VisibilityType.Hidden)}}
.
-
Note that 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).
-
Note that 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:
In the task pane 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.ShowPersonalInfo.Name = "Yes", UserProfile.MobilePhone = "06-12345678", Form.ShowPhoneIcon = "☑" (true) |
Output |
Contact: John Johnson Mobile phone ☎: 06-12345678 Email: john@bcompany.com |
Input | Form.ShowPersonalInfo.Name = "Yes", UserProfile.MobilePhone = "06-12345678", Form.ShowPhoneIcon = "☐" (false) |
Output |
Contact: John Johnson Mobile phone: 06-12345678 Email: john@bcompany.com |
Input | Form.ShowPersonalInfo.Name = "Yes", UserProfile.MobilePhone = "", Form.ShowPhoneIcon = "☑" (true) |
Output |
Contact: John Johnson Email: john@bcompany.com |
Input | Form.ShowPersonalInfo.Name = "No", UserProfile.MobilePhone = "06-12345678", Form.ShowPhoneIcon = "☑" (true) |
Output | Hidden text |
Related articles
Comments
Article is closed for comments.