Change the dialog options if the component is a child of a particular component | Community
Skip to main content
Level 3
May 2, 2023
Solved

Change the dialog options if the component is a child of a particular component

  • May 2, 2023
  • 3 replies
  • 1178 views

Hi everyone, We're planning to disable a field for a certain component if it is a child of a particular parent component.
I can't see any particular sample codes for it. 
I've been looking for some items (like granite rendercondition) but there isn't much sample for that on how to use it or if it really suits the need on our problem. Thanks!

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 Rohit_Utreja

Hi @lyonmartin,

 

One option would be to use java code. You can create a java class to fetch parent component and do the comparison.

In the component field, it can be added as mentioned below.

<granite:rendercondition
jcr:primaryType="nt:unstructured"
sling:resourceType="mysite/renderconditions/customcomparisoncomponent"/>

 

Please refer below URL for more details.

https://jpsoares.medium.com/aem-granite-render-conditions-438c804b1e5a

 

hope it helps!
Regards,

Rohit

 

3 replies

Rohit_Utreja
Community Advisor
Rohit_UtrejaCommunity AdvisorAccepted solution
Community Advisor
May 2, 2023

Hi @lyonmartin,

 

One option would be to use java code. You can create a java class to fetch parent component and do the comparison.

In the component field, it can be added as mentioned below.

<granite:rendercondition
jcr:primaryType="nt:unstructured"
sling:resourceType="mysite/renderconditions/customcomparisoncomponent"/>

 

Please refer below URL for more details.

https://jpsoares.medium.com/aem-granite-render-conditions-438c804b1e5a

 

hope it helps!
Regards,

Rohit

 

Anmol_Bhardwaj
Community Advisor
Community Advisor
May 2, 2023

Hi @lyonmartin ,

 

This is a scenario that I think would require extraClientlibs
https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/could-you-please-explain-what-is-extraclientlibs/m-p/197623 
Along with some custom script in your component. 
Component JS : 

- Based on the parent component, the child component can have a class if the condition is met.
Dialog JS:
You would need to hide/disable the field based on your conditions through a custom script.( JS )
You can look for the class present, and then if it is , you can disable/hide.

Nikhil-Kumar
Community Advisor
Community Advisor
May 2, 2023

@lyonmartin 
- You can use garnite:rendercondition here. By writing you logic in Sling Modal and check for the child of a parent component and then send the true value in blue snippet once you condition is fulfilled to show the field.

 

Set checkValue to true based on the logic to show the field and pass it to RenderCondition as below:

boolean checkValue = false;
request.setAttribute(RenderCondition.class.getName(),
new SimpleRenderCondition(true));