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

Fields become required ONLY after selecting a radio button or checkbox

Community Beginner ,
May 18, 2021 May 18, 2021

Copy link to clipboard

Copied

Please, help with script : Fields become required ONLY after selecting a radio button or checkbox (in this example -  "Other Country (please specify)").

 

Sample file in attachment.

 

Thanks.

TOPICS
PDF forms

Views

2.1K

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 2 Correct answers

Community Expert , May 18, 2021 May 18, 2021

As the custom calculation script of the drop-down field enter the following:

event.target.required = this.getField("Registered In").valueAsString=="1";

Votes

Translate

Translate
Community Expert , May 18, 2021 May 18, 2021

Use this as the whole code:

 

if (this.getField("Registered In").valueAsString=="1") {
	event.target.required = true;
	event.target.display = display.visible;
} else {
	event.target.required = false;
	event.target.display = display.hidden;
	event.value = event.target.defaultValue;
}

Votes

Translate

Translate
Community Beginner ,
May 18, 2021 May 18, 2021

Copy link to clipboard

Copied

Update attachment...

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 ,
May 18, 2021 May 18, 2021

Copy link to clipboard

Copied

As the custom calculation script of the drop-down field enter the following:

event.target.required = this.getField("Registered In").valueAsString=="1";

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 Beginner ,
May 18, 2021 May 18, 2021

Copy link to clipboard

Copied

Thank you. Works.

 

P.S. Is it possible to return the data from the drop-down menu (default) if you select the “Same” button after selecting “Different country (specify)” and choosing from the drop-down menu? A person can make a mistake when filling out.

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 ,
May 18, 2021 May 18, 2021

Copy link to clipboard

Copied

Sure. Add this line to that code:

if (this.getField("Registered In").valueAsString=="0") event.value = event.target.defaultValue;

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 Beginner ,
May 18, 2021 May 18, 2021

Copy link to clipboard

Copied

Thank you. Works great.

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 Beginner ,
May 18, 2021 May 18, 2021

Copy link to clipboard

Copied

if (this.getField("Registered In").valueAsString=="0") event.value = event.target.defaultValue;

 

Can you add more to this code to make the drop-down menu hidden again?

 

Thank you.

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 ,
May 18, 2021 May 18, 2021

Copy link to clipboard

Copied

Use this as the whole code:

 

if (this.getField("Registered In").valueAsString=="1") {
	event.target.required = true;
	event.target.display = display.visible;
} else {
	event.target.required = false;
	event.target.display = display.hidden;
	event.value = event.target.defaultValue;
}

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 Beginner ,
May 18, 2021 May 18, 2021

Copy link to clipboard

Copied

Perfect now.

 

Thank you.

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 Beginner ,
May 24, 2021 May 24, 2021

Copy link to clipboard

Copied

Hello

If there are several such combinations in the document on the page, then all fields of this type are triggered. Is there a way to make such fragments work in isolation from each other?

 

A sample file is attached.

 

Thank you.

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 Beginner ,
May 24, 2021 May 24, 2021

Copy link to clipboard

Copied

Hello

If there are several such combinations in the document on the page, then all fields of this type are triggered. Is there a way to make such fragments work in isolation from each other?

 

A sample file is attached.

 

Thank you.

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 Beginner ,
May 24, 2021 May 24, 2021

Copy link to clipboard

Copied

LATEST

Solved... Sorry. I have not changed the name of the field in the script. 🙂

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