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

How to conditionally format text fields based on input from multiple checkboxes?

Community Beginner ,
Feb 17, 2023 Feb 17, 2023

Copy link to clipboard

Copied

Hi, 

In a certain part of my form, I give the user 5 answer options (5 checkboxes). Multiple boxes can be checked. Now I wonder if it is possible, depending on how many checkboxes are checked, to show 0, 1, 2, 3 or 4 text fields (or even better: combined text fields) in the space below. Is this possible? If not, does anyone know which other Adobe software can handle this?

 

TOPICS
How to , JavaScript , PDF forms

Views

2.0K

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 1 Correct answer

Community Expert , Feb 17, 2023 Feb 17, 2023

It would be better to just connect checkboxes to text fields:

this.getField("Text Field1").display = this.getField("Check Box1").isBoxChecked(0) ? display.visible : display.hidden;
this.getField("Text Field2").display = this.getField("Check Box2").isBoxChecked(0) ? display.visible : display.hidden;
this.getField("Text Field3").display = this.getField("Check Box3").isBoxChecked(0) ? display.visible : display.hidden;
this.getField("Text Field4").display = this.getField("Check Box4").isBoxChecked(0
...

Votes

Translate

Translate
Community Expert ,
Feb 17, 2023 Feb 17, 2023

Copy link to clipboard

Copied

You can place fields and then show/hide them with a script depending on how many checkboxes are checked.

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 ,
Feb 17, 2023 Feb 17, 2023

Copy link to clipboard

Copied

Great. Could you also tell me how to do this? Would be much appreciated. 

What I want is that all fields are hidden, unless boxes are checked. The amount of boxes determine how many fields will show.

 

 

Schermafbeelding 2023-02-17 143748.png

And in an ideal situation, the fields would also refer to the boxes (in my form field1 is a continuation / explenation belonging to checkbox1). So Field 1 and 3 show when boxes 1 and 3 are ticked. And also below eachother, without empty space. but that seems really complex. A solution to my top question would be really 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 Expert ,
Feb 17, 2023 Feb 17, 2023

Copy link to clipboard

Copied

You can use this as custom calculation script in one of the text fields:

 

var c1 = this.getField("Check Box1").valueAsString;
var c3 = this.getField("Check Box3").valueAsString;
var t1 = this.getField("Text Field1");
var t3 = this.getField("Text Field3");

//Script to show/hide fields
if(c1!="Off" && c3!="Off"){
t1.display = display.visible;
t3.display = display.visible;}
else{
t1.display = display.hidden;
t3.display = display.hidden;}

 

You are right, to move field is more complex to achieve, but it can be done by using 'rect' property of a 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 Beginner ,
Feb 17, 2023 Feb 17, 2023

Copy link to clipboard

Copied

Thanks alot. It works. Since the given situation above is just one example of how users will answer, I am curious how to process all options in the code. options are:

no checks = no fields

c1 = t1

c2 = t2

c3 = t3

c4 = t4

c1+c2 = t1 +t2

c1+c3 = t1+t3 (like above, which works)

c1+c4 = t1+t4

c2+c3 = t2+t3

c3+c4 = t3+t4

if you can indicate whether this is possible and how that argumentation basically works, then I hope to be able to figure it out myself.

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 17, 2023 Feb 17, 2023

Copy link to clipboard

Copied

It would be better to just connect checkboxes to text fields:

this.getField("Text Field1").display = this.getField("Check Box1").isBoxChecked(0) ? display.visible : display.hidden;
this.getField("Text Field2").display = this.getField("Check Box2").isBoxChecked(0) ? display.visible : display.hidden;
this.getField("Text Field3").display = this.getField("Check Box3").isBoxChecked(0) ? display.visible : display.hidden;
this.getField("Text Field4").display = this.getField("Check Box4").isBoxChecked(0) ? display.visible : display.hidden;

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 ,
Feb 18, 2023 Feb 18, 2023

Copy link to clipboard

Copied

LATEST

Makes much more sense indeed. Thanks, this is what I needed!

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