Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

Checkbox will not uncheck

Avatar

Level 2

I have the following checkbox code:

if  (this.rawValue == 0)

{

     hc1.value.integer.value=0;

     hc2.value.integer.value=0;

     hc3.value.integer.value=0;

     hcgray.presence = "hidden";

     sfrhc1,value.integer.value=1;

     sfrhc2.value.integer.value=1;

     sfrhc3.value.integer.value=1;

     sfrhcgray.presence = "visible";

}

else

{

     hc1.value.integer.value=1; 

     hc2.value.integer.value=1;

     hc3.value.integer.value=1;

     hcgray.presence = "visible";

     sfrhc1,value.integer.value=0;

     sfrhc2.value.integer.value=0;

     sfrhc3.value.integer.value=0;

     sfrhcgray.presence = "hidden"

}

The problem I'm having is (1) For the hcgray to be hidden I have to select hidden in the object pallet and (2) I can only check the box I cannot uncheck it.

1 Accepted Solution

Avatar

Correct answer by
Level 6

Yes!  This is even better, but I didn't know until now that there is a presence property on the fill.  Try this:

if (this.rawValue == 0)

{  

    hc1.rawValue=0;

    hc2.rawValue=0;

    hc3.rawValue=0;

    hcgray.resolveNode("value.rectangle.#fill").presence = "hidden";

    sfrhc1.rawValue=1;

    sfrhc2.rawValue=1;

    sfrhc3.rawValue=1; 

    sfrhcgray.resolveNode("value.rectangle.#fill").presence = "visible";   

}  

else

{  

    hc1.rawValue=1;

    hc2.rawValue=1;

    hc3.rawValue=1;

    hcgray.resolveNode("value.rectangle.#fill").presence = "visible";

    sfrhc1.rawValue=0;

    sfrhc2.rawValue=0;

    sfrhc3.rawValue=0;

    sfrhcgray.resolveNode("value.rectangle.#fill").presence = "hidden";

}

View solution in original post

15 Replies

Avatar

Level 6

For starters, there is a comma instead of a period on the two marked lines:

if  (this.rawValue == 0)

{

     hc1.value.integer.value=0;

     hc2.value.integer.value=0;

     hc3.value.integer.value=0;

     hcgray.presence = "hidden";

     sfrhc1,value.integer.value=1;

     sfrhc2.value.integer.value=1;

     sfrhc3.value.integer.value=1;

     sfrhcgray.presence = "visible";

}

else

{

     hc1.value.integer.value=1; 

     hc2.value.integer.value=1;

     hc3.value.integer.value=1;

     hcgray.presence = "visible";

     sfrhc1,value.integer.value=0;

     sfrhc2.value.integer.value=0;

     sfrhc3.value.integer.value=0;

     sfrhcgray.presence = "hidden"

}

Avatar

Level 2

Sorry. I retyped my code on this page because I could not get it to copy. Just a typo on this page.

Avatar

Level 6

Oh well, thought it might be an easy one...

Are the other objects (hc1, etc) checkboxes?  I'm not familiar with the "value.integer.value" syntax; I usually set them with "hc1.rawValue = 1" and reset with "hc1.rawValue = 0".

Avatar

Level 2

Yes. The hc and sfrhc 1,2,3 are checkboxes and the hc sfrhc gray are rectangles. This actually worked before I added the hc items.

Avatar

Level 2

I reset my code to rawValue. It works fine except the same problem - once I check the box (this.rawValue == 0) it will not allow me to uncheck it.

Avatar

Level 6

Which checkbox is your code in?  Normally you don't have to explicitly set/clear the checkbox that you're clicking, it will automatically toggle. 

Avatar

Level 2

I am using this on an equipment audut form. I have a checkbox that is labeled installed. Normally the box is unchecked and the sfrhc lines are grayed out (sfrhcgray) and the Does Not Apply checkboxes (sfrhc1,2,3) are checked. If you click that box it grays out the hc part and sets the Does Not Apply check boxes and ungrays(?) and unsets the checkboxes for sfrhc.

Avatar

Level 2

Forgot to add this last post. The issue is, if I check the installed checkbox everything works properly. However if I decide to uncheck that box it will not uncheck.

Also, I have this code on several other items on this same form, not as long, usually only a couple of lines, and some of them work (check/uncheck) and some only allow you to check and not uncheck.

Avatar

Level 6

Hate to do this, but can you post the form, or a screenshot of the designer window with the form layout and heirarchy, as well as the current checkbox script?

Avatar

Level 2

Ok. Go to http://www.cclinksonline.com/form.html andthe entire form is available. The checkbox in question is on page 6. It is the first install checkbox.

Avatar

Level 6

So, I know what is going on, but I'm not sure why.  The issue is with the grey rectangles: if you comment out the presence toggling of the rectangles in both the if and else sections the checkbox actions work fine.  I think the problem is with the order of event firing and layout actions on the form; the rectangle presence gets changed but it is not reflected on the screen layout.  What I don't understand is why this affects the checkbox operation.  I would expect the checkboxes to still toggle; the only issue I would think you would see is that the rectangles don't change properly.

One of the pros of using a dynamic form is that the presence can change based on events without the need to relayout the entire form.  Maybe rectangles don't fit into this scheme.

Fortunately I have a better way to do this: instead of changing the presence of the rectangles, change the fill color.  This does work well on a dynamic form.  You're using a linear fill with a start color of gray and end color of white.  To make the rectangle invisible, change the start color to white (color value of "255,255,255") and it will be entirely white.  To make it visible change the start color back to gray (value "192, 192, 192" using the colors that you selected).  To do this you use the following statement:

   hcgray.value.rectangle.fill.color.value = color

The script for the "Chambers" installed checkbox should now look like this:

if  (this.rawValue == 0)

{

hc1.rawValue=0;

hc2.rawValue=0;

hc3.rawValue=0;

hcgray.value.rectangle.fill.color.value = "255,255,255"; // Set to white start color

sfrhc1.rawValue=1;

sfrhc2.rawValue=1;

sfrhc3.rawValue=1;

sfrhcgray.value.rectangle.fill.color.value = "192,192,192"; // Set to gray start color

}

else

{

hc1.rawValue=1;

hc2.rawValue=1;

hc3.rawValue=1;

hcgray.value.rectangle.fill.color.value = "192,192,192";  // Set to gray start color

sfrhc1.rawValue=0;

sfrhc2.rawValue=0;

sfrhc3.rawValue=0;

sfrhcgray.value.rectangle.fill.color.value = "255,255,255" // Set to white start color

}

You will need to do the same to the "Diverter" section.

Also, you are probably aware of this but you need to deal with the enabled state of the checkboxes within each section when the section is "Does Not Apply".  If you gray out the Chambers section, the user can still check/uncheck the Yes/No/Corrected checkboxes.

HTH,

Kevin

Avatar

Level 6

Actually I do know what's going on, and I apologize for not noticing this earlier.  Your pages are set up as Positioned content.  In order to have object presence change dynamically the objects need to be contained in subforms with Flowed content.

Based on the layout of your form I would go with the color change scheme.  At this point it would be a lot of work to change your form to flowed layout and have everything line up properly.

Kevin

Avatar

Level 2

I changed the code as you suggested and it works as predicted, however the text never shows because the screen is either gray or white.

Considering your input on changing presence and doing a color change, would there be a way to go from the color fill to no fill?

I am very new at this so have to ask alot of questions.

Avatar

Correct answer by
Level 6

Yes!  This is even better, but I didn't know until now that there is a presence property on the fill.  Try this:

if (this.rawValue == 0)

{  

    hc1.rawValue=0;

    hc2.rawValue=0;

    hc3.rawValue=0;

    hcgray.resolveNode("value.rectangle.#fill").presence = "hidden";

    sfrhc1.rawValue=1;

    sfrhc2.rawValue=1;

    sfrhc3.rawValue=1; 

    sfrhcgray.resolveNode("value.rectangle.#fill").presence = "visible";   

}  

else

{  

    hc1.rawValue=1;

    hc2.rawValue=1;

    hc3.rawValue=1;

    hcgray.resolveNode("value.rectangle.#fill").presence = "visible";

    sfrhc1.rawValue=0;

    sfrhc2.rawValue=0;

    sfrhc3.rawValue=0;

    sfrhcgray.resolveNode("value.rectangle.#fill").presence = "hidden";

}

Avatar

Level 2

Perfect!!!!!! This works great! I also remembered what you said earlier about the check boxes. I removed the Does Not Apply Boxes since they are not needed and then changed the code to make sure the other boxes are unchecked under the rectangle.

Thank you so much for your help.

I also had to go to docReady and add   hcgray.resolveNode("value.rectangle.#fill").presence = "hidden";

so that the page opened with the rectangle hidden. If not you had to cycle the check box 1 time to uncover.

Message was edited by: cclay53