Expand my Community achievements bar.

Going crazy! Objects not becoming hidden . . .

Avatar

Level 1

Hi,

I have a bunch of checkboxes and each one corresponds to a subform that becomes visible when the checkbox is either on (1) or neutral (2).  The subforms are hidden until the box is checked. But if I make a mistake while using the form in Adobe and check a box I don't need, when I uncheck it, the subform is not becoming hidden again. 

The first part of the code works fine:


if (eqc812.rawValue == 1|2) {

xfa.resolveNode("EQC812").presence="visible";

}


The rest that I have tried don't work at all!


else if (eqc812.rawValue == 0)  {

xfa.resolveNode("EQC812").presence="hidden";

}

else {

xfa.resolveNode("EQC812").presence="hidden";

}

else if (eqc812.rawValue == 0) {

xfa.resolveNode("EQC812").display=display.hidden;

}

else {

xfa.resolveNode("EQC812").display=display.hidden;

}

else if (eqc812.rawValue == 0) {

xfa.resolveNode("EQC812").hidden=true;

}

else {

xfa.resolveNode("EQC812").hidden=true;

}

As for display=display.hidden and hidden=true, if I recreated the visible part of the code with it, it made the visible part not work either. And I tried replacing "hidden" with "invisible".

I have made other forms where the if else if statement worked fine to make things visible and hidden.  Please help me, I am SOOO frusterated!!

4 Replies

Avatar

Level 10

Hi,

I will try and work through it with you. A few observations:

  • I don't think the first if statement will work, as the checkbox can only have two values "1" or "2" (if this is what you have set the checkbox binding to). The checkbox can only have two states (on or off) and the subform can only have two states (visible or invisible/hidden). Try the following in either the click event or the exit event of the checkbox:

if (this.rawValue == 1)

{

     xfa.resolveNode("EQC812").presence = "visible";

}

else

{

     xfa.resolveNode("EQC812").presence = "hidden";

}

  • I am not sure why you are resolving the node. I would be inclined to reference the object directly. form1.page1.EQC812.presence etc.
  • I am not familar with display (I am not sure if it is XFA Javascript). using the presence works in XFA so I would stick with that.
  • Also hidden = true is unlikely to work.

This should work. Good luck,

Niall

Avatar

Level 1

Hi Niall,

Thank you!! You have solved my problem by making me look at this a different way. Your code works because I can only have one raw value.  But I need the Neutral value to count as the box being checked and to show the previously hidden object. So I played around with it and this works for me:

if (eqc712.rawValue == 0) {

xfa.resolveNode("EQC712").presence="hidden";

}

else {

xfa.resolveNode("EQC712").presence="visible";

}

I have no idea why I have resolve node in there - I don't know what it does, a guy in my office told me to put it in and it works so . . . I use it.
I have another question that has been stumping me much worse though. Its slightly less important to my document but is confusing me much more.
I have a counter that counts each ticked checkbox, and for some reason I have a group of checkboxes that refuse to be counted.  Here's a piece of code that works and one that doesn't. 
if (xfa.resolveNode("ss.ssc1").rawValue==1|xfa.resolveNode("ss.ssc1").rawValue==2)
credits.rawValue=credits.rawValue+1;
if (xfa.resolveNode("id.idc11").rawValue==1|xfa.resolveNode("id.idc11").rawValue==2)
credits.rawValue=credits.rawValue+1;
Seriously confused by this, they look exactly the same. I have double checked names etc etc . . .
I tried this too but I know I have something wrong in here and can't find it.
if (form1.#subform[0].id.idc11.rawValue==1|form1.#subform[0].id.idc11.rawValue==2)
credits.rawValue=credits.rawValue+1;
Thanks for your help Niall, I had given up on using this document properly.

Avatar

Level 10

Hi,

I have never had call to use the on/off/neutral checkbox before, so yes I now see the binding. In essence it is still the same process - instead of testing two possible options, you are testing for three.

A couple of things, when using "or", it is better to use a double || which is a logical OR.

Seeing #subform[0] implies that the subform is not named. It is a really good ides (imho) to name subforms as you go, so that it makes it much easier to reference in script. It depends on the volume of script in your form, but I would be inclined to name them.

When you are in the script editor, if you hover over an object that you want to reference and press and old Control, the mouse will change into a 'V'. When you click the object it will insert the full reference into the script for you. Do this a couple of times, when objects are in unnamed subforms or on the master page and you will see when LC automatically uses xfa.resolveNode. When the objects are named, it will just give the minimum SOM.

xfa.resolveNode is needed sometimes. Like when you assign an object to a variable - when you want to use that variable to alter the object, you need to resolve it first. Also if there are unnamed objects or subforms, then the object has to be resolved. Where you have two objects sitting in the same subform and they have different names, then you don't need to resolve the nodes. I would be inclined to drop the xfa.resolveNode where possible. As far as I can recall it adds to the overload in a form, as it needs to continually go off an resolve objects in the middle of the script.

In relation to your counter I would be inclined to drop the xfa.resolveNode; change to || and check the events that the scripts are in (to make sure that they are firing at the correct time).

Good luck,

Niall

Avatar

Level 1

Thank you, just noticed that I should mark this as answered!