Expand my Community achievements bar.

Something is breaking this script

Avatar

Level 2

I've got a dead simple script that hides and shows a subform based on the value of a checkbox:

if (this.rawValue == 1) {

form1.Page.NextYearSubform.NYSubform.presence = "visible";

}

else {

form1.Page.NextYearSubform.NYSubform.presence = "hidden";

}

This works fine if it is the first event upon opening the form. But if any other click event fires (the form has lots of checkboxes and radio buttons), this script ceases to work. Anyone seen this before?

Thanks.

7 Replies

Avatar

Level 2

I fixed it by referencing the objects directly rather than hiding/showing the subform that contained them:

if (this.rawValue == 1) {

Title.presence = "visible";

Grade.presence = "visible";

Year.presence = "visible";

}

else {

Title.presence = "hidden";

Grade.presence = "hidden";

Year.presence = "hidden";

}

...But if anyone can explain why hiding/showing the subform didn't work I'd like to know.

Thanks.

Avatar

Level 7

So there is no confusion in livecycle, i always make sure when i have if (this.rawValue == 1) that i always have if (this.rawValue == 0) rather than just an else.

Avatar

Level 2

So two ifs rather than an if with an else.

Is else known to be unreliable?

Avatar

Level 2

I tried it with two ifs and it still wouldn't set presence = "visible".

Very strange.

Avatar

Level 2

I can test it with messageBox, so I know the script executes, but the property doesn't get set.

if (this.rawValue == 1) {

xfa.host.messageBox("One");

form1.Page.NextYear.NYSubform.presence = "visible";

}

if (this.rawValue == 0) {

xfa.host.messageBox("Zero");

form1.Page.NextYear.NYSubform.presence = "hidden";

}

Avatar

Level 7

Weird.

Do you need to have quotes around the value?

When you use the action builder, it uses quotes.

1467072_pastedImage_0.png

Avatar

Level 2

I've never needed quotes before, and like I said the script obviously runs because the xfa.host.messageBox statement works.

So it's something in the form that is preventing the script from setting the presence property of the subform. Perhaps something is scrambled in the XML, which I would be useless at debugging.

Not a big deal... I've worked around it by removing the objects from the subform.

Thanks.