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

Any way to create a tiered check-box?

Community Beginner ,
Feb 03, 2024 Feb 03, 2024

Copy link to clipboard

Copied

I am creating a PDF form, and I would ideally like to have a checkbox that has three states: unchecked, checked, or double-checked. I then want to use the state of the checkbox to drive the value of another field. I know how to do the last part, but not the first. I could use two checkboxes or even a drop-down, but neither of those fits what I have in mind. Ideally, the user would click the box once to check it, again to double-check it (which would have a distinct appearance), and a third time to uncheck it again.

Any suggestions or alternative ideas would be appreciated!

TOPICS
Modern Acrobat , PDF forms

Views

651

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 04, 2024 Feb 04, 2024

Copy link to clipboard

Copied

Hi @Nick311037523ol3 ,

 

Acrobat checkbox widgets don't have a double-check status, but the desired action that you're inquiring about may be accomplished may be by adding a conditional statement in your 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
Community Expert ,
Feb 04, 2024 Feb 04, 2024

Copy link to clipboard

Copied

You can use a button to do it. Try searching the forum for "tri-state fields".

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 04, 2024 Feb 04, 2024

Copy link to clipboard

Copied

Take a look at the toggle button samples at the bottom of this page.

https://www.pdfscripting.com/public/Free-Sample-PDF-Files-with-scripts.cfm

 

Creating a state buttons require maintaining a state value.  To implement a 3-state button the state value has to be stored in a persistent location that can handle 3 separate values, for example a hidden text field. In addition you'll need to store 3 images, one for each state. A single hidden button will work for this.

 

So, to implement a 3 state button you'll need

* One visible button (this UI for the button)

* One hidden text field (for storing the state data)

*One hidden button field (for storing the 3 state images)

 

Additional 3-state buttons can use the same hidden fields. However, you'll need to use a more advanced data storage technique with the hidden text field for storing state data for multiple buttons.  

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 04, 2024 Feb 04, 2024

Copy link to clipboard

Copied

Now that I'm looking at it. You can use the visible button caption to store the state data, even though the button is set to Icon Only, so the caption will never be shown.   The hidden text field is not needed, but you'll still need the hidden button to store the state icons. 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 04, 2024 Feb 04, 2024

Copy link to clipboard

Copied

Thanks Thom! I stumbled upon this other thread of you helping someone with something similar
https://community.adobe.com/t5/acrobat-discussions/tristate-button/td-p/10826731
I managed to get the visual behavior I wanted using a custom button like that, but can't seem to find a way to use the button state as a variable input to other calculations using this.getField("ButtonName").value

Am I missing something, or do buttons not have output values, or is this what you mean by having a hidden text field (for storing the state data)?

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 04, 2024 Feb 04, 2024

Copy link to clipboard

Copied

I've tried:

{
event.target.textColor = color.white;
event.target.buttonSetCaption("");
event.value = 0;;
}

to call the value of the button in another field's script. I've also tried:

{
event.target.textColor = color.white;
event.target.buttonSetCaption("");
var X = 0;
}

var Y;
this.Y = X;

to create a global variable to call in another field's script. Neither of these seems to work.

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 04, 2024 Feb 04, 2024

Copy link to clipboard

Copied

@Nick311037523ol3 ,

 

If I am not mistaken, buttons don't hold values.

 

 

 

 

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 04, 2024 Feb 04, 2024

Copy link to clipboard

Copied

Basically, I'm trying to use the state of the "checkbox" in another field to control how to calculate the value of that field. I've gotten it to work with a simple checkbox as well as with a dropdown menu, but the button doesn't seem to want to output a value, not even a string value based on the label.

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 04, 2024 Feb 04, 2024

Copy link to clipboard

Copied

I'm getting close. Using this script in the field I want the button state to influence seems to work, but the field doesn't update when the button is clicked; rather, it waits until some other field updates to update itself.

var obj = this.getField("ButtonName");
var C = obj.buttonGetCaption();

if (C == ""){
    event.value = 0;
} else if (C == "l"){
    event.value = 1;
} else if (C == "t"){
    event.value = 2;
}

Once I can get this to update when the button is clicked, I'll be good to go. 

 

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 04, 2024 Feb 04, 2024

Copy link to clipboard

Copied

Please explain which field and which script on the field. 

I'm assuming that the script in the latest post is on a text field where you want to display a value based on the state button?  

Also, is the tri-state button working?  

Clear and complete information is important. 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 05, 2024 Feb 05, 2024

Copy link to clipboard

Copied

@Thom Parker ,

 

I think I found one of your previous threads explaining to another user about the tri-state back in September 2021.

 

In the discussion below is the script that you did and it works perfectly:

 

 

In this particular case , I assume the problem is due to the user running his other scripts as a calculation script from textfields and expecting the scripts to return an exported value from button widget.

 

If I am not mistaken, and contrary to radio buttons or checkboxes, I've read some of your posts before explaning that this type of object cannot hold an export value.

 

So I played around with your script a little bit and employed it  as a Mouse-Up action for the button object and added to it a few lines to populate the text field with the desired values as the user  cycles through the button states.

 

 

 

switch(event.target.buttonGetCaption())
{
   case " ": 
      event.target.buttonSetCaption("0");
      this.getField("Text1").value = 0;

      break;
   case "0": 
      event.target.buttonSetCaption("1");
      this.getField("Text1").value = 1;

      break;

   case "1": 
      event.target.buttonSetCaption("t");
      this.getField("Text1").value = 2;

      break;

   default: 
      event.target.buttonSetCaption(" ");
      this.getField("Text1").value = "";
      break;
}

 

 

 

Hope it helps.

 

Maybe I am not on the left field this time around... LOL!

 

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 05, 2024 Feb 05, 2024

Copy link to clipboard

Copied

LATEST

See attachment, you can edit the script to change the characters and the colors.

This is a much simpler example.

 

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