Skip to main content
MM2016
Known Participant
August 7, 2020
Answered

Acrobat Pro How to set a check box with export value as read only depending on a drop down selection

  • August 7, 2020
  • 2 replies
  • 4680 views

Hi there

I have a drop down field with 4 options (A, B, C, D). I have a another set of 3 checkboxes with different export values (X, Y and Z).

If options A, B and C are selected, I want the Checkbox with export value Z to be read only and change color to gray.

Is this possible?

Thanks in advance.

MG

This topic has been closed for replies.
Correct answer Nesa Nurani

Hi ls

Sorry I should have made myself clearer at the start. I don't usually use Export Value in check boxes unless I want it to work like a radio button. Yes, Nesa's code is perfect if I had different field names.

So how should I tweak the script?

Thanks

MM

 


Hi MM, I must admit if the checkboxes has same name I'm not sure how to adapt code to that(I'm, sure it's simple) but it's beyond my current level 😉 so if ls_rbls can help you he is more then welcome. In the meantime if you want to use my code above and you want checkboxes to act as radio buttons I have workaround for you, name your checkboxes different (example: X,Y,Z) and use this code as mouse up event of each checkbox just change their names if you want, for checkbox "X" use:

if(event.target.isBoxChecked(0)){
this.getField("Y").checkThisBox(0,false);
this.getField("Z").checkThisBox(0,false);
}

 

for checkbox "Y" use:

if(event.target.isBoxChecked(0)){
this.getField("X").checkThisBox(0,false);
this.getField("Z").checkThisBox(0,false);
}

 

and for checkbox "Z" use :

if(event.target.isBoxChecked(0)){
this.getField("Y").checkThisBox(0,false);
this.getField("X").checkThisBox(0,false);
}

2 replies

ls_rbls
Community Expert
Community Expert
August 10, 2020

+++UPDATE

 

I just wanted to add to the answer to this question :

 

  •  I want the end user to only tick one box at the time. Similar to a radio button function but I don't want to use a radio button.

 

Here is what work for me:

 

 

var g = event.value;
var f =  this.getField("myDropdown");

if ((g =="A") || (g =="B") || (g =="C"))  {

f.checkThisBox(2, true);
 
this.getField(f.name+".2").fillColor =  ["G",0.7]; 

f.readonly = true;


}  else {


f.checkThisBox(2, false);

f.readonly = false;

f.fillColor = ["RGB",0.874,0.874,1];

}

 

 

 

Selecting any any item that is not A, B or C allows to continue to check  the boxes again. 

 

This part of the script this.getField(f.name+".2").   doesn't work with the readonly attribute though

 

You will get the last checkbox in color gray, checked automatically upon the A, B, C selections from the dropdown list, but then  it makes the enntire parent group of checkboxes read-only. I am not sure if you wanted to have the ability to continue to check other boxes when the third one was made read-only.

 

 I haven't been able to figure that one out yet. But this works as far as one selection at a time just like radio buttons would  behave.

try67
Community Expert
Community Expert
August 10, 2020

The readonly property is set at the field level, not the widget level, which means you can't set a single "widget" in a group of fields with the same name as read-only, while the others are not.

ls_rbls
Community Expert
Community Expert
August 10, 2020

That would be a great feature if it was somehow implemented to work with both checkboxes and radio buttons.

 

 

Thank you as usual for your guidance!

Nesa Nurani
Community Expert
Community Expert
August 7, 2020

Use this code as "Custom Calculation Script" of your dropdown field.

var a = event.value;
var x = this.getField("Z");
if(a == "A" || a == "B" || a == "C"){
x.readonly = true
x.fillColor = ["G", 0.7];
}
if(a == "D"){
x.readonly = false
x.fillColor = color.white;
}

 

 

 

 Don't forget to rename fields to your field names and change color white if you want any other color.

try67
Community Expert
Community Expert
August 7, 2020

This code will not work.

Known Participant
August 7, 2020

I tried to recreate fields and using Nesa code. If values in dropdown field are A,B,C checkbox with value of Z should be read only and have grey background,  If thats what OP wanted code is working fine.