Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

problems changing an element on a master page

Avatar

Level 3

Hi there,

I've been struggling with a problem all day.

I have a large document using multiple master pages. I want a button on one single page to make an element on one of the master pages to toggle the visibility. This should happen on any and all pages that use that particular master page.

So... here's my code:

if (this.rawValue == "2") {

  this.resolveNode("#pageSet.CoreMaster.nonDis").presence = "hidden";

}

if (this.rawValue != "2") {

  this.resolveNode("#pageSet.CoreMaster.nonDis").presence = "visible";

}

I've placed this on a radio button set which has values for 1=no and 2=yes

if the user selects yes (ie value 2) it makes the text field called 'nonDis visible - if they select no - it then hides it. The element nonDis is on the master page called CoreMaster.

It works! Well almost. It only works on the very first page of the document. It's visibility on all other pages (that use that particular master page) still have the nonDis text field as hidden.

Incidentally, thinking it was my form (it's abig form) that was at fault, I tried a brand new form wioth nothing but that one element but with two pages and got the same issue - hidden on the first page, but not on the second.

I have no idea why - can someone help?

Many thanks,

Sunil

1 Accepted Solution

Avatar

Correct answer by
Level 10

As the master pages are repeatable object, they also have index numbers like [0], [1] etc.

Your current expression is only referencing the first instance of your master page.

To reference all instances you need a loop function.

var mp = xfa.resolveNodes("#pageSet.CoreMaster[*].nonDis");

for (var i = 0; i < mp.length; i += 1) {

     mp.item(i).presence = this.rawValue != "2" ? "visible" : "hidden";

}

View solution in original post

3 Replies

Avatar

Correct answer by
Level 10

As the master pages are repeatable object, they also have index numbers like [0], [1] etc.

Your current expression is only referencing the first instance of your master page.

To reference all instances you need a loop function.

var mp = xfa.resolveNodes("#pageSet.CoreMaster[*].nonDis");

for (var i = 0; i < mp.length; i += 1) {

     mp.item(i).presence = this.rawValue != "2" ? "visible" : "hidden";

}

Avatar

Level 3

Thank you so much radzmar,

I had a feeling that it had something to do with requiring a loop of some description, but this level of programming is beyond me.

Thanks for helping me out here - couldn't have done it without you.

Sunil

Avatar

Level 3

ah, no, it didn't quite work - it's working on some master pages but not on others. As I've said this is the correct answer I'll post another question.