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

Required Fields Based on Drop Down

Community Beginner ,
Mar 20, 2025 Mar 20, 2025
I'm creating a form where I have people registering for an event.
There is a drop down list for users to select 0-4 people in attendance. Below that, we have 4 spaces for each person attending.
I'm looking for a script that will only show the field and make it required based on the number of people.
 
Ex)
---User selects 0 (0 Value) people in attendance from the dropdown (labelled as FEG)
Fields "NameA", "NameB", "NameC", and "NameD" are hidden and not required.
 
---User selects 1 (225 Value) person in attendance from the dropdown (labelled as FEG)
Field "NameA" is made visible and required. Fields "NameB", "NameC", and "NameD" are hidden and not required.
 
---User selects 2 (450 Value) people in attendance from the dropdown (labelled as FEG)
Fields "NameA" and "NameB" are made visible and required. Fields , "NameC", and "NameD" are hidden and not required.
 
---User selects 3 (675 Value) people in attendance from the dropdown (labelled as FEG)
Fields "NameA", "NameB", and "NameC" are made visible and required. Fields "NameD" is hidden and not required.
 
---User selects 4 (900 Value) people in attendance from the dropdown (labelled as FEG)
Fields "NameA" and "NameB", "NameC", and "NameD" are made visible and required.
 
I've tried a few scripts, based off of other things I've seen, but it's not working out for me.
TOPICS
How to , PDF forms
192
Translate
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
1 ACCEPTED SOLUTION
Community Expert ,
Mar 20, 2025 Mar 20, 2025

Use this code pattern. Place it as the custom Calculation script of "FEG":

 

if (event.value=="0") {
	this.getField("NameA").display = display.hidden;
	this.getField("NameA").required = false;
	this.getField("NameB").display = display.hidden;
	this.getField("NameB").required = false;
	this.getField("NameC").display = display.hidden;
	this.getField("NameC").required = false;
	this.getField("NameD").display = display.hidden;
	this.getField("NameD").required = false;
	this.resetForm(["NameA", "NameB", "NameC", "NameD"]);
} else if (event.value=="1") {
	this.getField("NameA").display = display.visible;
	this.getField("NameA").required = true;
	this.getField("NameB").display = display.hidden;
	this.getField("NameB").required = false;
	this.getField("NameC").display = display.hidden;
	this.getField("NameC").required = false;
	this.getField("NameD").display = display.hidden;
	this.getField("NameD").required = false;
	this.resetForm(["NameB", "NameC", "NameD"]);
} // etc.


I added to it a command to clear the hidden fields, so you don't get values that shouldn't be there when exporting the form data.

View solution in original post

Translate
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 ,
Mar 20, 2025 Mar 20, 2025

Does 225 Value mean 225 is the export value for a selection of 1, and 450 is the export value for a selection of 2, etc.?

Translate
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 Beginner ,
Mar 23, 2025 Mar 23, 2025
LATEST

Yes, that is correct.

Translate
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 ,
Mar 20, 2025 Mar 20, 2025

Use this code pattern. Place it as the custom Calculation script of "FEG":

 

if (event.value=="0") {
	this.getField("NameA").display = display.hidden;
	this.getField("NameA").required = false;
	this.getField("NameB").display = display.hidden;
	this.getField("NameB").required = false;
	this.getField("NameC").display = display.hidden;
	this.getField("NameC").required = false;
	this.getField("NameD").display = display.hidden;
	this.getField("NameD").required = false;
	this.resetForm(["NameA", "NameB", "NameC", "NameD"]);
} else if (event.value=="1") {
	this.getField("NameA").display = display.visible;
	this.getField("NameA").required = true;
	this.getField("NameB").display = display.hidden;
	this.getField("NameB").required = false;
	this.getField("NameC").display = display.hidden;
	this.getField("NameC").required = false;
	this.getField("NameD").display = display.hidden;
	this.getField("NameD").required = false;
	this.resetForm(["NameB", "NameC", "NameD"]);
} // etc.


I added to it a command to clear the hidden fields, so you don't get values that shouldn't be there when exporting the form data.

Translate
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 Beginner ,
Mar 23, 2025 Mar 23, 2025

That works wonderfully!

Thank you so much! 

Translate
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