Highlighted

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

Explorer ,
Aug 07, 2020

Copy link to clipboard

Copied

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

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);
}

Topics

PDF forms

Views

105

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

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

Explorer ,
Aug 07, 2020

Copy link to clipboard

Copied

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

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);
}

Topics

PDF forms

Views

106

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
Participant ,
Aug 07, 2020

Copy link to clipboard

Copied

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.

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
Reply
Loading...
Most Valuable Participant ,
Aug 07, 2020

Copy link to clipboard

Copied

This code will not work.

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
Reply
Loading...
Community Beginner ,
Aug 07, 2020

Copy link to clipboard

Copied

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.

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
Reply
Loading...
Most Valuable Participant ,
Aug 07, 2020

Copy link to clipboard

Copied

This line is incorrect:

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

If it's working correctly it's pure luck.

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
Reply
Loading...
Participant ,
Aug 07, 2020

Copy link to clipboard

Copied

Well it is working as intended (unless OP had something else in mind) I did try it before posting code, I thought, if (a == "A" || "B" || "C"){ means if values are A,B or C?

I'm still learning myself can you please explain so I can learn for next time? thx

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
Reply
Loading...
Most Valuable Participant ,
Aug 07, 2020

Copy link to clipboard

Copied

I'm sorry if I was a bit curt. It's very good that you're learning and also trying to help others!

JavaScript doesn't support this kind of "shorthand" comparisons. It has be written out in full, like this:

(a == "A" || a == "B" || a == "C")

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
Reply
Loading...
Participant ,
Aug 07, 2020

Copy link to clipboard

Copied

Oh, I knew that 🙂 my brain just turns off sometimes, thx for pointing that out il fix post above,

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
Reply
Loading...
Community Beginner ,
Aug 07, 2020

Copy link to clipboard

Copied

But why did code still work?

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
Reply
Loading...
Most Valuable Participant ,
Aug 07, 2020

Copy link to clipboard

Copied

Because the || "B" || "C" part returned true no matter what the value of the "a" variable was.

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
Reply
Loading...
Explorer ,
Aug 08, 2020

Copy link to clipboard

Copied

Thank you all for your help.

The entire script did not work for me. Is there any other way? Thanks.

 

var amendmentType = this.getField("Z");

if ((event.value == "A")||
     (event.value == "B")||
     (event.value == "C"))

{
amendmentType.readonly = true;
amendmentType.fillColor = ["G",0.7];

}

else
{
amendmentType.readonly = false;
amendmentType.fillColor = ["RGB",0.874,0.874,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
Reply
Loading...
Participant ,
Aug 09, 2020

Copy link to clipboard

Copied

What exactly is not working for you? Did you rename your checkbox field to "Z"?

Here is a file I used to try your code, try it and let me know is that what you wanted or you need something else.

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
Reply
Loading...
Adobe Community Professional ,
Aug 09, 2020

Copy link to clipboard

Copied

You need to be more specific and state where are you trying to run the script from. 

 

Also, if you have placed this script as custom calculation script, the field properties changes will commit once  you click outside of the dropdown menu after making a selection.

 

The script is working fine on my end.

 

Check that field names in your script match the actual fieldname, like for example, if your fieldname is "Z" is actually types as upper case "Z" not "z".

 

 

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
Reply
Loading...
Adobe Community Professional ,
Aug 09, 2020

Copy link to clipboard

Copied

I apologize, it seems that I was posting my reply around the same time as 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
Reply
Loading...
Explorer ,
Aug 09, 2020

Copy link to clipboard

Copied

Hi there

Thanks again. I checked your attachment. The reason why it didn't work for me is that I have identical Field Name (Amendment Type) for all the checkboxes (with different Export Values) as 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.

How would you code it in that case.

Thanks

MM

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
Reply
Loading...
Adobe Community Professional ,
Aug 09, 2020

Copy link to clipboard

Copied

I don't want to sound rude but that is a different question and Nesa's code answered your inquiry correctly.

 

However, when I was testing the srcipt I had the same observation and I tried to go that route.

 

It didn't work for me.

 

 

The code has to be modified slightly differently.

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
Reply
Loading...
Explorer ,
Aug 09, 2020

Copy link to clipboard

Copied

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

 

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
Reply
Loading...
Participant ,
Aug 09, 2020

Copy link to clipboard

Copied

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);
}

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
Reply
Loading...
Explorer ,
Aug 09, 2020

Copy link to clipboard

Copied

Hi Nesa

Thanks for the workaround. Great to know that.

Thank you  for your help. Much appreciated.

Cheers

MM

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
Reply
Loading...
Explorer ,
Aug 09, 2020

Copy link to clipboard

Copied

Hi Nesa

That alternative solution worked perfectly.

Thanks so much.

Cheers

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
Reply
Loading...
Adobe Community Professional ,
Aug 09, 2020

Copy link to clipboard

Copied

You got it right.

 

I was getting stuck with this too.

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
Reply
Loading...
Adobe Community Professional ,
Aug 09, 2020

Copy link to clipboard

Copied

Don't forget to mark Nesa's answer as correct solution.

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
Reply
Loading...
Explorer ,
Aug 09, 2020

Copy link to clipboard

Copied

I marked the wrong comment and I can't find a button to undo 😞 let me know if you know.

But I also marked Nesa's solution as correct answer 🙂

Thanks

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
Reply
Loading...
Explorer ,
Aug 11, 2020

Copy link to clipboard

Copied

Hi Nesa

Thanks again for your help.

MM

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
Reply
Loading...
Adobe Community Professional ,
Aug 10, 2020

Copy link to clipboard

Copied

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

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
Reply
Loading...
Most Valuable Participant ,
Aug 10, 2020

Copy link to clipboard

Copied

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.

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
Reply
Loading...
Adobe Community Professional ,
Aug 10, 2020

Copy link to clipboard

Copied

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!

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
Reply
Loading...
Most Valuable Participant ,
Aug 10, 2020

Copy link to clipboard

Copied

It's possible to do it by creating fields with unique names and using a script to reset all other members of the "group" when one of them is ticked. It's actually not too complicated to do... And then you could enable/disable some of them without problems.

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
Reply
Loading...
MM2016 LATEST
Explorer ,
Aug 11, 2020

Copy link to clipboard

Copied

Thanks you everyone for your help on this.

MM

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
Reply
Loading...
Resources
One Stop Solution for Acrobat
Edit a PDF