Adobe Forms - Simplified Field Notation Quirks
Copy link to clipboard
Copied
I am training my staff on how to prepare great fillable forms for users by taking advantage of simplified field notation to have the form autocomplete many of the forms calcuations.
Today, I reviewed a form one of my users made that was not calculating correctly.
They were calculating a field like this:
([Variable1]+[Variable 2])*[Variable 3]
The actual calculation should have been something like this:
(1+2)*2 = 6
Instead, adobe was performing this calculation:
(12)*2 = 24
Through testing. I determined the square brackets were the issue. Whenever variables are [bracketed] and summed, Adobe seems to concatenate the values instead of sum them. (So instead of 1+2, they combine the 1 and 2 for a value of 12).
I can't find any documentation anywhere regarding this behavior. I recall reading in the past that [bracketing] your variables helped if you accidentally had variable names with spaces or other forbidden characters. Turns out, it's now a source of error.
Anyone experienced this, or can point me towards documentation explaining this behavior?
Copy link to clipboard
Copied
What names does you use for the fields?
Copy link to clipboard
Copied
They were using names like Field Number One but the spaces of course break calculations, so they were bracketing them like [Field Number One] to get around that limitation. We fixed it by making them rename all variables like FieldNumberOne. Just trying to understand this bracketing behavior.
Copy link to clipboard
Copied
This is not error, square brackets changed value to object.
Copy link to clipboard
Copied
Understood. Is there any documentation out there that speaks to this? My team has been using [Bracketing of variables] when they have spaces in the names. This is the first time it's become an issue. I fixed it by making them use BracketingofVariables as a name instead, but want to learn WHY this behavior occurs.
Copy link to clipboard
Copied
Squared brackets are often used to define arrays, if your field name has space use backslash instead.
example:
Field 1 would be used like this Field\ 1
Copy link to clipboard
Copied
Thank you for your help. Can you point me to the documentation around this?
Copy link to clipboard
Copied
I don't think such documentation exists, not officially anyway, but Nesa's advice is correct.
I would recommend you use a script if you have complex field names or want to perform more advanced calculations.
Copy link to clipboard
Copied
Thanks for the reply try76.
We're in the beginning stages of creating complex fillable forms with varying calculations. I'm doing my best peicing together advice from various forums, but was hoping to hear there was some hidden documentation somewhere I was missing. Sad to hear there isn't.
However, thanks to various forum threads like this, I was able to write some javascript calculation code today that compares one calculated field variable to another, and returns the higher value of the two as the value of yet another field. Gonna post it here to help anyone else.
//Javascript Calculation to Compare two form field variables and return the higher of the two in a given field
Copy link to clipboard
Copied
Simplified field notation is actually converted to JavaScript using a fairly simple process, which is why spaces and punctuation can cause severe problems. And there are other situations where using spaces and punctuation in a name can be misinterpreted. It's is a good practice to use some simple naming rules. Such as "Never use spaces or punctuation in a field name, unless you know exactly how it will be used." Make names as short as possible, but long enough to clearly communicate the fields role on the form. Use common prefixes to group related fields. Use a uniform naming format for fields representing rows and columns in a table.
You'll find more info on form scripting and naming here:
https://www.pdfscripting.com/public/PDF-Form-Scripting.cfm
Use the Acrobat JavaScript Reference early and often

