Something is breaking this script

Avatar

Avatar

ScottDM

Avatar

ScottDM

ScottDM

16-04-2018

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.

Accepted Solutions (0)

Answers (7)

Answers (7)

Avatar

Avatar

ScottDM

Avatar

ScottDM

ScottDM

16-04-2018

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.

Avatar

Avatar

MinusZero

Avatar

MinusZero

MinusZero

16-04-2018

Weird.

Do you need to have quotes around the value?

When you use the action builder, it uses quotes.

1467072_pastedImage_0.png

Avatar

Avatar

ScottDM

Avatar

ScottDM

ScottDM

16-04-2018

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

Avatar

ScottDM

Avatar

ScottDM

ScottDM

16-04-2018

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

Very strange.

Avatar

Avatar

ScottDM

Avatar

ScottDM

ScottDM

16-04-2018

So two ifs rather than an if with an else.

Is else known to be unreliable?

Avatar

Avatar

MinusZero

Avatar

MinusZero

MinusZero

16-04-2018

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

Avatar

ScottDM

Avatar

ScottDM

ScottDM

16-04-2018

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.