Modifying component post-rendering

Avatar

Avatar
Validate 1
Level 2
blkhatpersian
Level 2

Likes

4 likes

Total Posts

32 posts

Correct reply

1 solution
Top badges earned
Validate 1
Boost 3
Boost 1
Applaud 5
Affirm 1
View profile

Avatar
Validate 1
Level 2
blkhatpersian
Level 2

Likes

4 likes

Total Posts

32 posts

Correct reply

1 solution
Top badges earned
Validate 1
Boost 3
Boost 1
Applaud 5
Affirm 1
View profile
blkhatpersian
Level 2

22-03-2016

Hi all,

I am wanting to dynamically "hide" a parsys on one of my AEM pages when it is in edit mode. I am wanting to do this with in-code script, taking advantage of the "cq:widgets" clientLibrary. I have a javascript file where I am using the CQ.WCM.getEditable method to find a component by giving it a path and then calling the .hide() method. 

Here is my simple code: 

function hideparsys(path){ var parsysComp = CQ.WCM.getEditable(path); if(parsysComp){ alert(path); } parsysComp.hide(); // makes the parsys Invisible }

I call that code at the bottom of my page-rendering .jsp file where this parsys is included. Here is that code: 

<script type="text/javascript"> { hideparsys("<%= currentNode.getPath()+ /pars"); } </script>

The error I get in the console is that parsysComp is null when I attempt to call .hide(). My hideparsys code is being executed before the parsys in my .jsp is rendered or made availabe by AEM and that is why I cannot access it.

Does anyone have any suggestions in-script on when/how to modify a component after it has been rendered? 

Thanks,
Ali

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Validate 1
Level 10
edubey
Level 10

Likes

277 likes

Total Posts

1,502 posts

Correct reply

392 solutions
Top badges earned
Validate 1
Give Back 50
Give Back 5
Give Back 3
Give Back 25
View profile

Avatar
Validate 1
Level 10
edubey
Level 10

Likes

277 likes

Total Posts

1,502 posts

Correct reply

392 solutions
Top badges earned
Validate 1
Give Back 50
Give Back 5
Give Back 3
Give Back 25
View profile
edubey
Level 10

22-03-2016

Try using this at the end of template level. It will execute once page is loaded...

(function() { CQ.WCM.on("editablesready", function() { CQ.WCM.getEditable(your_node_path + "/parsys/*").hide(); }); })();

Do replace this your_node_path with your own

Answers (1)

Answers (1)

Avatar

Avatar
Validate 1
Level 2
blkhatpersian
Level 2

Likes

4 likes

Total Posts

32 posts

Correct reply

1 solution
Top badges earned
Validate 1
Boost 3
Boost 1
Applaud 5
Affirm 1
View profile

Avatar
Validate 1
Level 2
blkhatpersian
Level 2

Likes

4 likes

Total Posts

32 posts

Correct reply

1 solution
Top badges earned
Validate 1
Boost 3
Boost 1
Applaud 5
Affirm 1
View profile
blkhatpersian
Level 2

22-03-2016

That was it, thank you edubey!