Skip to main content
Known Participant
December 14, 2023
Answered

Make field mandatory based on radiobutton selection

  • December 14, 2023
  • 2 replies
  • 2161 views

I have a group (Group2) of radiobuttons with 3 options.
Option1

Option2

Option3

 

When Option1 is selected I want field Text14 to be mandatory. When option 2 or 3 are selected it should not be mandatory.
I have tried putting code in mouse Up/Javascript

if (event.target.value == "Yes")

{this.getField("Text14").required = true;}

But it's not working.

What am I doing wrong here?

This topic has been closed for replies.
Correct answer Nesa Nurani

and is it at all possible to make a group mandatory bases on an option chosen in another group.

I noticed the groups don't have the custom calculation field


If you need a custom calculation script, you can place it in any text field, you can even make a text field and hide it and place script in it. Let's say you want to make Group5 required, depending on selections from Group2 and Group4, a custom calculation script:

var g2 = this.getField("Group2").valueAsString;
var g4 = this.getField("Group4").valueAsString;
var g5 = this.getField("Group5");

g5.required = (g2 === "Option1" && g4 === "Option2") ? true : false;

 

 

2 replies

Nesa Nurani
Community Expert
Community Expert
December 14, 2023

Your choice is 'Option1' not "Yes".

Use this as custom calculation script of the field you wish to make required;

event.target.required = this.getField("Group2").valueAsString === "Option1" ? true : false;
Known Participant
December 14, 2023

Thank you this worked perfectly

Bernd Alheit
Community Expert
Community Expert
December 14, 2023

Use also a else

Known Participant
December 14, 2023

I tried this

if (event.target.value == "Yes")

{this.getField("Text14").required = true;}
else

{this.getField("Text14").required = false;}

 

but still not working