Skip to main content
Participant
May 10, 2024
Question

Reset radio group to hidden when form is cleared

  • May 10, 2024
  • 4 replies
  • 755 views

I have reached my wits end trying to figure something out unsuccessfully and so I am writing here for the first time ever, hoping the commuty can assist.

 

I've created a benefits enrollment form that has two sets of radio button groups that are connected, "Medical" and "Medical Waive Reason" with the latter having an initial display value of hidden.

 

What I need to happen:

  1. If an employee chooses to waive coverage in the medical plan thus selects the "Decline Coverage" radio button, the "Medical Waive Reason" radio buttons become visible.
  2. If an employee chooses to enroll in the medical plan and selects one of the other "Medical" group radio options (not "Decline"), then the "Medical Waive Reason" radio buttons return to hidden and, if any button was selected, values cleared.
  3. If the entire form is cleared, therefore the "Decline Coverage" radio box is cleared, then the "Medical Waive Reason" radio buttons return to initial state of hidden, values cleared if any.

 

What I've accomplished:

I've managed to successfully solve for items 1 & 2.  On the "Decline Coverage" radio button > Action Tab > Run a JavaScript on mouse up, I used the following script that works:

 

var radio2 = this.getField("Medical Waive Reason");
if (event.target.value=="Off")
{
radio2.display = display.hidden;
radio2.value = "";
}
if (event.target.value=="Med 4- waive")
{
radio2.display = display.visible;
} else {
radio2.display = display.hidden;
radio2.required = false;
radio2.value = "";
}

 

Where I need help:

I cannot figure out the JavaScript for how to return the "Medical Waive Reason" radio group back to the initial Hidden state when "Decline Coverage" is CLEARED.  Can you help solve this mystery???  Please!!!

This topic is closed to new replies. Start a new post to keep the conversation going.

4 replies

try67
Community Expert
Community Expert
May 10, 2024

Use a Calculation script to do this, instead of a Mouse Up one. The former is triggered when the form is cleared, the latter isn't. You can use a hidden text field for this. The only thing you need to adjust in your code, basically, is to replace event.target.value with this.getField("Decline Coverage").value.

However, there's an error in your code. If "Medical Waive Reason" is a radio-button group then setting its value to "" will not clear it. You need to set it to "Off".

Participant
June 26, 2024

Thank you so much for your response.  Some follow up questions:

 

1. I don't see a place to add a Calculation script to a radio group.  I attach an image here of the Decline Coverage properties options.  Could advise where I can find the area to add a Calculation script?

 

2. I've reviewed your script suggestions and updated to the best of my understanding.  Is the below script now written correctly?  And would the script remain [somewhere] on the Decline Coverage radio button or would it go elsewhere?

var radio2 = this.getField("Medical Waive Reason");
if (this.getField("Decline Coverage").value=="Off")
{
radio2.display = display.hidden;
radio2.value = "Off";
}
if (this.getField("Decline Coverage").value=="Med 4- waive")
{
radio2.display = display.visible;
} else {
radio2.display = display.hidden;
radio2.required = false;
radio2.value = "Off";
}

try67
Community Expert
Community Expert
June 26, 2024

1. No, you won't find it. As I wrote: You can use a hidden text field for this.

2. The script is written correctly, but the logic behind it is flawed. The second part of it will completely override the first one, so you can remove that part entirely:

if (this.getField("Decline Coverage").value=="Off")
{
radio2.display = display.hidden;
radio2.value = "Off";
}

Another issue is the required property. If you want the field to be required when visible you have to set it as true. Otherwise there's no need to set it as false in your code, as it only needs to happen once.