Adding string to text field while allowing future edits.

Explorer ,
Feb 27, 2021 Feb 27, 2021

Copy link to clipboard

Copied

This is a multi faceted question. I am looking to have a calculation result in a string being inserted into a text field without interupting what was or will be there. for instance. 

f.value = "userstring" + "generated string"

or being able to add a custom string after f.value already has the generated string.

I am also interested in doing this with numbers. I assume it works similarly because Acrobat handles value as both str and num unless defined. The trick is I need the user number to be what the field resets to. This is a sample of what I am working on. This is placed a combobox with the values to be added.

if (event.willCommit){
if (event.value==1)
{f.value=f.value + 2;}
else if (event.value==2)
{f.value=f.value + 3;}
}

 The issue is the values just add on top of one another. I need a way to remove the change and return to the users original value before adding the next generated number. I am new to this so any advice or a point in the right direction would be super helpful. Thanks for reading.

TOPICS
General troubleshooting, JavaScript, PDF forms

Views

54

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
community guidelines
Most Valuable Participant ,
Feb 27, 2021 Feb 27, 2021

Copy link to clipboard

Copied

Use the Format event, instead of Calculate. It adds the string without changing the field's actual value, so when the user edits it the added string doesn't get added over and over again.

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
community guidelines
Explorer ,
Feb 28, 2021 Feb 28, 2021

Copy link to clipboard

Copied

LATEST

Hello again and thank you for your response! This worked with the strings to a point but still overwrote whatever was in the field prior. I would like to be able to have text be added to whatever text was already there. As for the numbers, I seem to still be running into issues regardless of event type. I think I can be clearer about my problem. I would like a user to fill in a number of thier choosing into a text field. Later in the form there is a combobox that adds modifiers to that number. As the code works now, if someone put in 1 as the value then selected +2, the result is 3 which is expected. However, if they change thier mind and select +1 instead, the result becomes 4. I have no way of returning to the original value of 1 the user entered. 

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
community guidelines