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

500

Likes

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

Adobe Community Professional , 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";

Likes

Translate

Translate
Adobe Community Professional , 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;
}

Likes

Translate

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

Copy link to clipboard

Copied

Update attachment...

Likes

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
Adobe Community Professional ,
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";

Likes

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.

Likes

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
Adobe Community Professional ,
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;

Likes

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.

Likes

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.

Likes

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
Adobe Community Professional ,
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;
}

Likes

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.

Likes

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.

Likes

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.

Likes

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. 🙂

Likes

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