• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
4

Make field mandatory based on radiobutton selection

Explorer ,
Dec 14, 2023 Dec 14, 2023

Copy link to clipboard

Copied

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?

TOPICS
Create PDFs

Views

394

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 3 Correct answers

Community Expert , Dec 14, 2023 Dec 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;

Votes

Translate

Translate
Community Expert , Feb 02, 2024 Feb 02, 2024

Use this as custom calculation script of that text field:

var rb = this.getField("Group2").valueAsString;
event.target.required = (rb === "Option1" || rb === "Option4") ? true : false;

Votes

Translate

Translate
Community Expert , Feb 09, 2024 Feb 09, 2024

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;

 

 

Votes

Translate

Translate
Community Expert ,
Dec 14, 2023 Dec 14, 2023

Copy link to clipboard

Copied

Use also a else

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 14, 2023 Dec 14, 2023

Copy link to clipboard

Copied

I tried this

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

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

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

 

but still not working

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 14, 2023 Dec 14, 2023

Copy link to clipboard

Copied

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;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 14, 2023 Dec 14, 2023

Copy link to clipboard

Copied

Thank you this worked perfectly

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 02, 2024 Feb 02, 2024

Copy link to clipboard

Copied

Thank you for your previous help. I'm still working on the same form, but needed to add an option.

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

Option2

Option3

Option4

 

When Option1 or Option4 are selected I want field Text14 to be mandatory. When option 2 or 3 are selected it should not be mandatory.
I've been working with if, or, else. but I can't seem to find the right code

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 02, 2024 Feb 02, 2024

Copy link to clipboard

Copied

Use this as custom calculation script of that text field:

var rb = this.getField("Group2").valueAsString;
event.target.required = (rb === "Option1" || rb === "Option4") ? true : false;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 09, 2024 Feb 09, 2024

Copy link to clipboard

Copied

Thank you for your help. The form works so much better already.

What if I want to make a field mandatory based on 2 groups?

So if Group 2 option 1 is true and Group 4 option 2 is true

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 09, 2024 Feb 09, 2024

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 09, 2024 Feb 09, 2024

Copy link to clipboard

Copied

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;

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 09, 2024 Feb 09, 2024

Copy link to clipboard

Copied

thank you so much. I'm trying this on Monday

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 12, 2024 Feb 12, 2024

Copy link to clipboard

Copied

LATEST

It works perfectly. thank you so much

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines