Articles in this section

How to use fields or Groups with custom visibility within a Group

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.

 

 
  • The use of nested Groups is not recommended by Templafy.
    Whenever possible use standalone Group bindings.

 

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:

ao_groupbinding.png

 

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.

 

 
  • In the expression you also need to add the Group visibility!
    If you would not add the part Equals(Form.ShowText, "Yes", then the visibility for the form field can show unexpected results.
  • Note that behind {{Form.Adjective}} no space is used:

    ao_groupbindingnospace.png

    The reason for this is that if no adjective is shown, you don't end up with 2 spaces ("The<space><space>brown").

    But if the adjective is shown, where does the space come from?
    This is solved by adding the space in the Binding field, behind {{Form.Adjective}}:

    ao_bindingwithspace.png

 

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):

ao_userprofilefields.png

 
  • The 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.

 
  • The use of nested Groups is not recommended by Templafy.
    Whenever possible use standalone Group bindings.

 

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:

  1. Create a data source named 'YesNo' and add the values 'Yes' and 'No' to the Name column. The result looks like this:

    ao_datasourceyesno.png

  2. 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'.

  3. 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'.

  4. 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.

  5. In the Visibility field select Custom Visibility, then in Visibility expression field type this expression: {{IfElse(Equals(Form.ShowPersonalInfo.Name, "Yes"), VisibilityType.Visible, VisibilityType.Hidden)}}:

    ao_visibilityexpression.png

  6. Click Add to template.

  7. 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.

  8. In the Visibility field select Custom Visibility, then in Visibility 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.

     

  9. Click Add to template.

  10. 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.

  11. In the Visibility field select Custom Visibility, then in Visibility 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 after Form.ShowPhoneIcon. This is because it's a checkbox form field that returns the boolean value 'true' (when it's checked).

  12. Click Add to template.

  13. In the template the result looks like this:

    ao_multiplegroups.png

    In the task pane the result looks like this:

    ao_multiplegroupstaskpane.png

    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:

ao_composer.png

 

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

 

 

visibility smart fields groups nested groups
Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Article is closed for comments.