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.

Reset radiobutton list when check box unchecked

Avatar

Level 2

I have a static PDF registration form that I am working on using LiveCycle Designer 8.2. I would like to learn how to have a radiobutton list reset when a particular check box is unchecked.

When registering for the event, users have the option of attending 1 of the 4 optional afternoon workshop sessions. I have successfully made the workshop radiobuttons hidden until the check box is checked using the following code:

(check box is named "Reg4" -- this is where they say "yes" I'm going to attend 1 of the 4 workshops,

radiobutton list of the 4 workshops is named "RadioButtonList3")

      topmostSubform.Page1.Reg4::change - (JavaScript, client)

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

       this.resolveNode("RadioButtonList3").presence = "hidden";

When the user unchecks the "Reg4" checkbox after they have selected 1 of the 4 workshops, that radiobutton is still checked.

What I'm looking for is to have the radiobutton list reset (or again hidden) when the Reg4 button is unchecked (after previously being checked).

I hope my description is clear. Is this possible?

13 Replies

Avatar

Level 10

You can set the radiobutton with "":

RadioButtonList3.rawValue = "";

Your if statement should work, but the zero shouldn't be in quotes:

if (this.rawValue == 0) {

  this.resolveNode("RadioButtonList3").presence = "hidden";

}

You would normally do this as part of the script you're using to to show the radiobuttons:

if (this.rawValue == 1) {

  RadioButtonList3.presence = "visible";

}

else {

  RadioButtonList3.presence = "hidden";

}

Avatar

Level 2

Thanks for the reply, Jono.

What I like about your code is that it brings up a message when the user clicks the Reg4 check box

     "RadioButtonList3 cannot be left blank."

But, if the user 1) checks the Reg4 check box; then 2) selects one of the radio buttons; then 3) unchecks the Reg4 check box, the radiobutton is still selected.

What I'm looking for is after the check box is checked and then unchecked, the radiobutton list is cleared or hidden.

Does this sound doable?

Avatar

Level 2

Just saw that I was the one that added the error message :-)

Here's the code:

topmostSubform.Page1.RadioButtonList3::calculate - (FormCalc, client)

if (Reg4 == "0") then

          RadioButtonList3.access = "readOnly"

          RadioButtonList3.mandatory = "disabled"

else

          RadioButtonList3.access = "open"

          RadioButtonList3.mandatory = "error"

endif

I welcome all ideas on getting this list to hide/reset. Thanks!!

Avatar

Level 10

To clear it as well you need to add the: rawValue = ""

if (Reg4 == "0") then

          RadioButtonList3.rawValue = ""

          RadioButtonList3.access = "readOnly"

          RadioButtonList3.mandatory = "disabled"

else

          RadioButtonList3.access = "open"

          RadioButtonList3.mandatory = "error"

endif

Avatar

Level 2

Thanks, Jono. This is so close!

It didn't work when I changed the code to match your above suggestion but it did when I added the rawValue line to the Reg4 code:

    

topmostSubform.Page1.Reg4::change - (JavaScript, client)

if (this.rawValue == 1) {

  RadioButtonList3.presence = "visible";

}

else {

  RadioButtonList3.rawValue = ""

  RadioButtonList3.presence = "hidden";

}

Now, when the user unchecks the Reg4 checkbox the radiobuttons reset but are no longer hidden. This means they can select one and that cannot be an option for them. (In this case, it appears to the user that if they have a radiobutton selected then they are going to be registered for an event but this is in fact not true. They are only registered if the Reg4 box is checked.)

I assumed the "else...hidden" would have taken care of that.

Do I have a syntax error or is it something else?

I'm a newbie learning as I go and I appreciate all of your time helping me with this!

Avatar

Level 10

You need a semicolon at the end of: RadioButtonList3.rawValue = "";

JavaScript statements need a semicolon at the end. FormCalc statements don't

Sorry, you were bouncing between JavaScript and FormCalc and I didn't notice that the FormCalc code was on the calculate event for the radio buttons - I'd get rid of that and drive it all from the checkbox.

Avatar

Level 2

I like your suggestion of combining the scripts (much cleaner document) but now I'm moving further away from the goal.

When I run this, the radiobuttons are available when I first preview but then are hidden when I select the Reg4 checkbox. Also, the message no longer shows up (not a biggie but not sure why it went away).

When I read this in layman's terms, to me it says if Reg4 is checked then radiobuttons are visible, open for input & error message is mandatory. Otherwise, radios are blank, the fields are hidden, access is readonly, and the error message is disabled.

Do I really need all of those line of script, especially, in the else section? Or am I required to balance the lines on the if and else sections?

topmostSubform.Page1.Reg4::change - (JavaScript, client)

if (this.rawValue == 1) {

  RadioButtonList3.presence = "visible";

  RadioButtonList3.access = "open";

  RadioButtonList3.mandatory = "error";

}

else {

  RadioButtonList3.rawValue = "";

  RadioButtonList3.presence = "hidden";

  RadioButtonList3.access = "readOnly";

  RadioButtonList3.mandatory = "disabled";

}

Avatar

Level 10

Because you had some script on the radio buttons make sure you get rid of all that script so nothing is interfering.

This script should make the radio buttons visible on checking the checkbox and then hidden on unchecking the checkbox. If the radio buttons are showing by default you need to set them to hidden on the Object palette.

It's possible the values of the checkbox might have been changed, the default is 0 = Off and 1 = On. So check on the Binding tab of the Object palette and see what the values are.

You can take the readOnly and open statements out as they aren't really needed because you are hiding the radio buttons. But basically, everything you turn on (or off) needs to be turned off (or on) again.

So, the following should work as long as the value for the On state of the chcckbox is equal to 1.

if (this.rawValue == 1) {

  RadioButtonList3.presence = "visible";

  RadioButtonList3.mandatory = "error";

}

else {

  RadioButtonList3.rawValue = "";

  RadioButtonList3.mandatory = "disabled";

  RadioButtonList3.presence = "hidden";

}

Avatar

Level 2

Makes sense that anything you turn on/off, you must also turn off/on.

There is no script on RadioButtonList3.

The off value in Reg4 Binding is set to 0.

I did a copy/paste of your suggestion above so I didn't make any typos.

When I change the radiobutton field presence to hidden, they don't show up when I click Reg4.

Unfortunately, the radiobuttons do not hide but do reset when unclicking Reg4.

Also it doesn't tell me that the radiobuttonlist cannot be blank which I thought that's what the "mandatory=error" line makes happen.

Here's what I have for Reg4 (and nothing for radiobuttonlist):

topmostSubform.Page1.Reg4::change - (JavaScript, client)

if (this.rawValue == 1) {

  RadioButtonList3.presence = "visible";

  RadioButtonList3.mandatory = "error";

}

else {

  RadioButtonList3.rawValue = "";

  RadioButtonList3.mandatory = "disabled";

  RadioButtonList3.presence = "hidden";

}

Very frustrating. Are static pages able to have hidden fields?

I appreciate all of your time on this. Just not sure what to try at this point.

Avatar

Level 10

Ah, I guess it's the static pdf...thought hiding a field would still work. I don't deal with static pdfs much. Just tried it and that seems to be the problem.

In which case I think you're limited to controlling the access and mandatory settings.

if (this.rawValue == 1) {

  RadioButtonList3.access = "open";

  RadioButtonList3.mandatory = "error";

}

else {

  RadioButtonList3.rawValue = "";

  RadioButtonList3.mandatory = "disabled";

  RadioButtonList3.access = "readOnly";

}

Avatar

Level 2

Thank you again, Jono, for your reply. I was worried that the Static PDF was the trouble but I just couldn't take no for an answer!

If you're willing, I'd be happy to send you my file but am unable to post publicly.

In an earlier version the RadioButtonList3 is hidden when first viewing the file. It was done using FormCalc. (I know you said don't mix the languages but, hey, it worked!) Also, I found a post you had last year in the discussion "Prompt User to click checkbox (radio button)" where you described a message box using Java. I snagged that and put it on the enter event of the Reg4 field.

When I preview the PDF, this is what I now have:

  • Upon first view, RadioButtonList3 is hidden and am unable to select (perfect)
  • When I check the Reg4 box, I get the "You will be registered for a..." warning message (perfect)
  • I can now make a selection in the RadioButtonList3 (perfect)
  • If I uncheck the Reg4 box without making a selection on RadioButtonList3, the RadioButtonList3 again hides (perfect)
  • If I check the Reg4, then make a selection on RadioButtonList3, and then uncheck the Reg4 box, the RadioButtonList3 is reset (perfect)
  • BUT the RadioButtonList3 is still visible and a selection can now be made (not perfect because the Reg4 box is now unchecked and the user will only be registered for the event if Reg4 is checked)

#1 RadioButtonList3 will hide only if it has not been selected and reset first.

#2 The warning message only appears the first time Reg4 is checked.

These 2 items somehow seem related. Is there something that tells it "use this code when you first open the document but act differently once you've started checking boxes" so it only acts as I intend on the first go-around?

Here's all of my code:

- - - - - - - - - - -

  topmostSubform.Page1.RadioButtonList3::calculate - (FormCalc, client)

if (Reg4 == "0") then

          RadioButtonList3.access = "readOnly"

else

          RadioButtonList3.access = "open"

endif

- - - - - - - - - - -

topmostSubform.Page1.Reg4::change - (JavaScript, client)

if (this.rawValue == 1) {

  RadioButtonList3.presence = "visible";

}

else {

          RadioButtonList3.rawValue = "";

  RadioButtonList3.presence = "hidden";

}

topmostSubform.Page1.Reg4::enter - (JavaScript, client)

if (RadioButtonList3.rawValue == "") {

     xfa.host.messageBox("You will be registered for an Optional Workshop ONLY if this box is checked. Don't forget to tell us which workshop you will be attending.");

     this.rawValue == null;

}

- - - - - - - - - - -

So sorry for the lengthy post. I'm open to any ideas that anyone may have.

This certainly is a learning experience!

Avatar

Level 10

Yeah unfortunately it is the static pdf, so there's not much you can do about it unless you redo the form as dynamic.

You can mix FormCalc and JavaScript, just not on the same event.

Avatar

Level 2

Thanks for all of your help, Jono. I appreciate all of the time you spent helping me out.