Show and hide multiple text boxes and form fields depending on dropdown form selection or any other posible button selection. | Community
Skip to main content
NikoGR
April 4, 2023
Solved

Show and hide multiple text boxes and form fields depending on dropdown form selection or any other posible button selection.

  • April 4, 2023
  • 1 reply
  • 1751 views

Hello everyone,
Attached is a "small"😔 topic that I'm trying to solve and need help.


Description:
Show and hide multiple text boxes and form fields depending on dropdown form or any other posible button selection.
If I may formulate it in Excel manners.
If "Niko" is in the drop down, only the fields intended for Niko should appear.

But if "Maria" is selected, only the fields intended for Maria should be displayed.

If "Niko & Maria" is selected, all fields should appear.


How can I do this?


A suggested solution with step-by-step instructions would be very nice 🙂.

 

Working with Adobe Acrobat Pro 2020 (2020.005.30441)

 

Thanks in advance.🙂

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by AsifChowdhury

Hello @nikogr 

Here I am giving the idea of how you can achieve it with a dropdown selector.
Your requirement is not supported by AEM OTB. So you need to create a clientlib and do some custom code for this. To achieve this you need to write a clientlib for the author dialog.

Step 1: Add your clientlib by "extraClientlibs" in your dialog.
Step 2: You can choose the "select" component which supports multiple values to select with "granite:data" => 'cq-dialog-dropdown-showhide-target=".target-item-show-hide"'

 

<type jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/form/select" granite:class="cq-dialog-dropdown-showhide" fieldLabel="Type" multiple="{Boolean}true" name="./type"> <granite:data jcr:primaryType="nt:unstructured" cq-dialog-dropdown-showhide-target=".target-item-show-hide"/> <items jcr:primaryType="nt:unstructured"> <option jcr:primaryType="nt:unstructured" text="Targeted Item" value="targetedItem"/> </items> </type>

 

Step 3: Add "granite:data" => 'showhidetargetvalue="targetedItem"' in the targeted component and 'granite:class="hide target-item-show-hide"'

 

<targetedItem jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/container" granite:class="hide target-item-show-hide"> <granite:data jcr:primaryType="nt:unstructured" showhidetargetvalue="targetedItem"/>

 

Step 3: You can grab the selected items from this "select" component in the associated clientlib js as an array/list

 

let selectedItemList = $('.cq-dialog-dropdown-showhide').values;

 

Step 4: You can also grab all targeted item

 

let targetedItemClass = $(element).data("cqDialogDropdownShowhideTarget"); // targetedItem class which is provided in "granite:data" in select component let targetedItemList = $(targetedItemClass);

 

Step 5: Then you can loop through the targeted item list and check if any item's "showhidetargetvalue" exist on the selected item list and filter out these items

 

var filteredItem = []; targetedItemList.each((idx, targetedItem) => { let targetedItemValue = $(targetedItem).data('showhidetargetvalue'); if(selectedItemList.includes(targetedItemValue)){ filteredElement.push($(targetedItem)); } })

 

Step 6: Now you can show/hide those filtered items.

 

filteredElement.forEach(element => element.removeClass('hide'));

 

1 reply

AsifChowdhury
Community Advisor
AsifChowdhuryCommunity AdvisorAccepted solution
Community Advisor
April 7, 2023

Hello @nikogr 

Here I am giving the idea of how you can achieve it with a dropdown selector.
Your requirement is not supported by AEM OTB. So you need to create a clientlib and do some custom code for this. To achieve this you need to write a clientlib for the author dialog.

Step 1: Add your clientlib by "extraClientlibs" in your dialog.
Step 2: You can choose the "select" component which supports multiple values to select with "granite:data" => 'cq-dialog-dropdown-showhide-target=".target-item-show-hide"'

 

<type jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/form/select" granite:class="cq-dialog-dropdown-showhide" fieldLabel="Type" multiple="{Boolean}true" name="./type"> <granite:data jcr:primaryType="nt:unstructured" cq-dialog-dropdown-showhide-target=".target-item-show-hide"/> <items jcr:primaryType="nt:unstructured"> <option jcr:primaryType="nt:unstructured" text="Targeted Item" value="targetedItem"/> </items> </type>

 

Step 3: Add "granite:data" => 'showhidetargetvalue="targetedItem"' in the targeted component and 'granite:class="hide target-item-show-hide"'

 

<targetedItem jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/container" granite:class="hide target-item-show-hide"> <granite:data jcr:primaryType="nt:unstructured" showhidetargetvalue="targetedItem"/>

 

Step 3: You can grab the selected items from this "select" component in the associated clientlib js as an array/list

 

let selectedItemList = $('.cq-dialog-dropdown-showhide').values;

 

Step 4: You can also grab all targeted item

 

let targetedItemClass = $(element).data("cqDialogDropdownShowhideTarget"); // targetedItem class which is provided in "granite:data" in select component let targetedItemList = $(targetedItemClass);

 

Step 5: Then you can loop through the targeted item list and check if any item's "showhidetargetvalue" exist on the selected item list and filter out these items

 

var filteredItem = []; targetedItemList.each((idx, targetedItem) => { let targetedItemValue = $(targetedItem).data('showhidetargetvalue'); if(selectedItemList.includes(targetedItemValue)){ filteredElement.push($(targetedItem)); } })

 

Step 6: Now you can show/hide those filtered items.

 

filteredElement.forEach(element => element.removeClass('hide'));

 

NikoGR
NikoGRAuthor
April 10, 2023

Thank you very much this is one of the best step by step descriptions

I have seen in this forum so far!

 

Before I have any additional questions that I would certainly like to ask later if I could 😊.

 

Will try it out later this week and give feedback.

 

thx again.

AsifChowdhury
Community Advisor
Community Advisor
April 10, 2023

Sure, and most welcome.