Copy link to clipboard
Copied
I'm not sure if the title makes sense, but this is what I am trying to do; in the text box, I am typing in a state's abbreviation and need the abbreviation to be in parenthesis, but I don't want to have to put in the parenthesis every time. Is it possible to just type in the two letters but the output of it would switch to the letters be surrounded by the parenthesis? textbox1: I type in IL, output: (IL)
Copy link to clipboard
Copied
I found the answer to my own question
if (event.value) event.value = "(" + event.value + ")";
Copy link to clipboard
Copied
I found the answer to my own question
if (event.value) event.value = "(" + event.value + ")";
Copy link to clipboard
Copied
You can do that with a simple custom calculation script in the text box. Try this:
Right-click the text field → Properties → Calculate → Custom calculation script
Paste this code:
if (event.value) {
event.value = "(" + event.value.replace(/[()]/g, "") + ")";
}This will automatically wrap whatever you type (like IL) in parentheses, even if you forget to add them yourself.
Copy link to clipboard
Copied
A Calculation script is a poor (and possibly outright dangerous) solution to this issue. Never use a calculation script to act on the value entered into a field, because it has the potential to cause an infinate loop.
The correct location for such a script is any of the events that are triggered on data entry into the field. In this instance the Validate event is the best choice since it is triggred after the data is being (but not quite) commited to the field.
Keep your original solution and make sure to place the code into the Custom Validation Script for the field.
Copy link to clipboard
Copied
Yes that’s totally possible, and how you do it depends on the platform or language you’re using for the text box.
Copy link to clipboard
Copied
The following custom format script is the best solution:
if(event.value)
{event.value="("+event.value+")"}
https://pdfautomationstation.substack.com/p/custom-format-for-pdf-fields
Copy link to clipboard
Copied
Format or Validation? Depends on the requirements for the final field value.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now