Display Value in PDF Text Field On Condition

New Here ,
Feb 14, 2019 Feb 14, 2019

Copy link to clipboard

Copied

Hello,

I am trying to set up a form that will display the word "standard" in a field next to a paired checkbox if checked but otherwise keep the value of what the user types.

Right now, I have this in the custom calculation script for the text field called upper1:

var upper1= this.getField("upper1");

if (this.getField("Check1").value != "Off")

upper1.value = "Standard"

else

upper1.display = display.visible

Is there a different way that doesn't require overriding the value of upper1? I'd like to not overwrite the user-inputted value if possible and just have it selectively display the user value or not. User value could be blank if they don't want it.

Alternatively, I'd like to set it to display the export value of the checkbox when checked and the user-inputted value if unchecked.

TOPICS
Acrobat SDK and JavaScript

Views

106

Likes

translate

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

Adobe Community Professional , Feb 16, 2019 Feb 16, 2019
So lets be clear about what you are trying to do. On your form there is a text field next to a check box. User's can enter text into the text field.  If the check box is checked, then the word "Standard" is appended or prefixed onto to text the user entered? The problem with this process. is that if the value of the field is modified you need to be able to parse the text field to remove the word standard. This is (slightly) problematic. It's much easier to have two fields as Bernd suggests. Or t...

Likes

translate

Translate

Translate
Adobe Community Professional ,
Feb 14, 2019 Feb 14, 2019

Copy link to clipboard

Copied

Use 2 fields. One with the value Standard. The other for the user input.

Likes

translate

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
New Here ,
Feb 16, 2019 Feb 16, 2019

Copy link to clipboard

Copied

I don't have the space for that.

Alternatively being able to clear out "standard" if unchecking but not over-riding any then user inputted value when I move to another line would be helpful.

Likes

translate

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 ,
Feb 16, 2019 Feb 16, 2019

Copy link to clipboard

Copied

So lets be clear about what you are trying to do. On your form there is a text field next to a check box. User's can enter text into the text field.  If the check box is checked, then the word "Standard" is appended or prefixed onto to text the user entered?

The problem with this process. is that if the value of the field is modified you need to be able to parse the text field to remove the word standard. This is (slightly) problematic. It's much easier to have two fields as Bernd suggests. Or to use the format event to add the appearance of the word "Standard', rather than changing the value of the text field.

To use the formatting solution, do this. Remove the calculation script.  Add this code to a custom format script for the text field.

if (this.getField("Check1").value != "Off")

    event.value = "Standard - " + event.value;

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

Likes

translate

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