how to show dynamic fields on dialog ? | Community
Skip to main content
Level 2
January 10, 2023
Solved

how to show dynamic fields on dialog ?

  • January 10, 2023
  • 4 replies
  • 4864 views

Hi All,

 

I have a requirment,  dynamic data source dropdown if select one value i have to show the selected value related dialog fields on the dialog page with colliseble layout and checkboxes.

example :   

dropdown :  value selected is "adobe".

 

1 headline :  products

checkbox 1

checkbox 2

2 headline :  ........

checkbox 1

checkbox 2

------- 

------

n.

 

These headline and checkbox are dynamic. we can't hardcode these in crxde dialog fields. we have to create dialogs dynamically. 

Would appreciate any help.

 

like:  on selection of dorpdown value show one popup window with all dynamic dialogs etc... with custom javascript. any example please for this. 

 

 

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 arunpatidar

Hi @arunpatidar ,

Sure. We are working on the headless project. content authors will assign this third party json data to a page. Once the page is published, we will send this page json with unique id to other system. based on this data (json) content from the published page will be dispalyed.

example json:

"offer"["10% off or more","15% off or more","20% off or more","25% off or more","30% off or more"].  etc...

 

Note: Currently the site is on java frame work application. we are migrating to AEM. 

 

thanks in advance. 

 


if you want to expose the 

"offer"["10% off or more","15% off or more","20% off or more","25% off or more","30% off or more"]. you can put maybe you can create in RTE or Text field or Textarea as text field, 

 

why you need to create options(dropdown, checkbox)

 

4 replies

Saravanan_Dharmaraj
Community Advisor
Community Advisor
January 10, 2023
Level 2
January 10, 2023

Hi @saravanan_dharmaraj ,

 

I want to show the checkbox based on the selection of dynamic dropdown.  when I select any value in dropdown i want to show checkboxes dynamically on the page properties dialog.  checkbox values are also dynamic and coming from 3rd party services.

 

 Hope you understand. 

Sady_Rifat
Community Advisor
Community Advisor
January 11, 2023

Hello @naresh536 ,

I created a similar type of dialog generation last year. My problem was like this:
I have a component, Component dropdown fields are dynamic. Based on the selection fields checkboxes were shown and hidden which was also dynamic. And all those data came from a service REST API.

 

My Solution:

I create a dialog like this, where the selected items and checkbox was not present.

 

 

At the time of dialog loading, I created the rest of the fields by using Java under /apps/myproj/component/mycomponet/cq:dialog/...
For this, I created a service user and give that user READ, WRITE, MODIFY, DELETE permission. (/apps/myproj/component/mycomponet)

 

And the Java code is something like this. Hope you understand.

Cons:
Since we write under /apps, in the parallel time of authoring value will be changed by other authors.
In my case, this component was not heavily used and need to configuration sometimes. That's why the overlapping change was very rare.

Level 2
January 11, 2023

Hi @sady_rifat ,

 

Thanks for the response. writing under apps is not recomanded. 

 

arunpatidar
Community Advisor
Community Advisor
January 11, 2023

You can check out to get reference how to create granite/Coral field dynamically.

https://aemlab.blogspot.com/2022/01/aemaacs-touch-ui-dialog-dynamic-dropdown.html 

Arun Patidar
Level 2
January 11, 2023

Hi @arunpatidar ,

 

Thanks for providing the link. dropdown datasource is not sutabile for our use case.

let me explain my query again.

I have a drop down. When I select a value in dropdown ajax call will be triggered and  data has to be displayed as shown below. headline and checkbox  values are coming form 3rd party service which are dynamic. onload of dialog headline and checkbox should be hidden.

 

             dropdown --- selected

headline 1

 checkbox 1

 checkbox 2

headline 2

 checkbox 1

 checkbox 2

 

-----------------------------

and could you please also assist me on, how to add a coral.accordion fileds with checkboxes using coral UI javascript when we select a value in dropdown. which has to be added under the dropdown. 

 

Would appreciate any help.

 

arunpatidar
Community Advisor
Community Advisor
January 12, 2023
Arun Patidar
Sady_Rifat
Community Advisor
Community Advisor
January 12, 2023

Hello @naresh536 ,
Since you don't want to create a node under /apps there are another solutions.

Solution 1:

You can use Datasource.

Here is a sample code, where you will call an HTML file and on that HTML you will call a Java Model class. That model will call the API and create a json for you.

XML:

<myList
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/select"
fieldLabel="Select An Item"
name="./selectItem">
<datasource
jcr:primaryType="nt:unstructured"
sling:resourceType="/apps/my-proj/datasource/speciality/speciality.html"/>
</myList>

HTML:

<sly data-sly-use.data="com.myProj.modal.MyModel"></sly>

Java:

List<Resource> resourceList = new ArrayList<>();
ValueMap vm = new ValueMapDecorator(new HashMap<>());
vm.put("value",value);
vm.put("text",text);
resourceList.add(new ValueMapResource(resolver, new ResourceMetadata(), JcrConstants.NT_UNSTRUCTURED, vm));

DataSource ds = new SimpleDataSource(resourceList.iterator());
this.getRequest().setAttribute(DataSource.class.getName(), ds);

 

Solution 2:

You call Java Servlet directly from the dialog XML

XML:

<myList
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/select"
fieldLabel="Select An Item"
name="./selectItem">
<datasource
jcr:primaryType="nt:unstructured"
sling:resourceType="your/servlet/path"
parameter="optional your value"/>
</myList>

Java:

Same as the previous one.

 

Reference Link: https://levelup.gitconnected.com/aem-populate-a-drop-down-with-a-data-source-edafada90cc4

Level 2
January 13, 2023

Hi @sady_rifat ,

 

Thanks for your response. I think Data source will work for key value. I want to show these checkbox inside arrodion.  Could you please let me know any possibility using datasource.

Thanks in advance.