Expand my Community achievements bar.

Nomination window for the Adobe Community Advisor Program, Class of 2025, is now open!

Dynamic node creation at runtime

Avatar

Level 1

Can we create nodes in the cq dialog at runtime?

The requirement is the dialog initially would only have a single dropdown with few fixed fields. So, when an option from the dropdown is selected let's say a value great is selected so when this action happened in the dropdown now it should map the value great to a json which has which component does great map to. Let's say great --- > mapped to "textfield". Now as soon as the backend mapping is done there should be a node created in the same dialog below the dropdown referring to textfield. Can someone help with the approach. we have tried few approaches, but any leads are welcome. TIN

 

8 Replies

Avatar

Level 4

Is the requirement to show or hide a field based on dropdown selection?

Avatar

Level 1

No. Not exactly hiding or showing fields. But when the dropdown value ex: "great" is selected, it is mapped to a OOTB component. According to that mapping we have to create a node at runtime.

 

Avatar

Level 4

Do you mean that component should be added as a child component? Why do you want to change the dialog nodes? It is not recommended to change dialog nodes dynamically. Content change is fine.

Avatar

Level 1

I'm working on something. Yes, it is not recommended but could you please share if there is a way that you know of to add the nodes in jcr repository at in runtime?

Avatar

Level 4

If you want to add a node, use a dialog listener, call a servlet which will perform jcr operations. I am not sure whether this will work in AEM Cloud.

Some dialog listener reference which calls servlet - https://kiransg.com/tag/dialog-level-listener/

Avatar

Community Advisor

@Preethi1234  I see there is no need of creating dialog field on fly. Instead have the textfield hidden by default and show/hide based on you dropdown change listener.

Avatar

Level 1

I strongly recommend avoiding the complexity of creating dialog nodes at runtime. Instead, consider using a well-established practice of showing or hiding fields based on the value selected in a drop-down menu. You can even group multiple fields together to enhance the user experience.

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager-blogs/show-hide-cq-dialog-... 

Avatar

Administrator

@Preethi1234 Did you find the suggestions helpful? Please let us know if you require more information. Otherwise, please mark the answer as correct for posterity. If you've discovered a solution yourself, we would appreciate it if you could share it with the community. Thank you!



Kautuk Sahni