These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Field populated by another field but can be written over

nerdaggro
Registered: Mar 16 2010
Posts: 12
Answered

Hello! I have a field that pulls from another field using getField (code below). But I want users to be able to overwrite the data. I'm thinking this is an if statement, but don't know how to script it.

event.value = this.getField("FieldName").value
Thanks!

My Product Information:
Acrobat Pro 8.1.7, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Is the code in a calculation script? There is a way to do this.

What you have to do is detect user entry, and then use this info to block the calculation.

Use the Keystroke Script:
if(!event.willCommit)event.target.bDetect = true;else if(event.value == "")event.target.bDetect = false;

Now, in the calculation script
   event.rc = !event.target.bDetect;event.value = this.getField("..").value;

If the user enters data into the field it sticks, but if they delete everything from the field it reverts back to the calculation.
The code will work while the PDF is open. However, the state data (event.target.bDetect) is lost when the PDF is closed. If you want to maintian the calculation override this data will have to be saved with the form and restored when it is reopened.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

nerdaggro
Registered: Mar 16 2010
Posts: 12
Thanks, Thom. Where do I enter the Keystroke script? I know you can enter scripts under Actions, Validate and Calculate. I might be looking in the wrong spot, but those are the only areas I know where you can add script.

Quote:
However, the state data (event.target.bDetect) is lost when the PDF is closed. If you want to maintian the calculation override this data will have to be saved with the form and restored when it is reopened.
I'm extending features to this PDF for Reader. How will this be affected?
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
The keystroke script is located on the Format Tab. Select "Custom" under the format selections.

I've got a couple of articles on entering scripts:
http://www.acrobatusers.com/tutorials/2006/scripts_form_fields
http://www.acrobatusers.com/tutorials/2006/formatting_text_fields

Reader rights won't affect this feature.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

nerdaggro
Registered: Mar 16 2010
Posts: 12
It works! Thank you!

The only problem is some fields are formatted as a phone number and now it doesn't format it for me. I found custom scripts in the forums for formatting a number like 000.000.0000 but I want it to do a standard (000) 000-0000.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Ok so you need a custom format script. As long as there are the correct number of digits in the input you could use something very simple like this

event.value = util.printx("(999) 999-9999",event.value);

if you need 7 digit entry you can use an "if" to separate out two different format statments. You might also want to use a validation script to make sure the data is entered correctly.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

nerdaggro
Registered: Mar 16 2010
Posts: 12
Thank you!
ddalben
Registered: Jun 22 2010
Posts: 3
I'm having the same issue in creating a PDF in LiveCycle. I select the option "Calculated - User Can Override". I can even enter an Override message which pops up but the manually entered value is always erased.

I tried following the directions above but I couldn't find a "Keystroke" area to enter the script.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
If you have a LiveCycle form then overriding a calculated field is a completely different technique.

Do you mean that the calculated value is erased? or that the calculation script is overwriting the manually entered value?

After manual entry the field value the calcultion script is blocked, so there is some other code on the form that is overwriting the field, not the calculation.

I actually wrote an aticle on overriding LC calcuations, posted here:
http://www.pdfscripting.com/public/department52.cfm

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

ddalben
Registered: Jun 22 2010
Posts: 3
When I add something in manually, my manual entry is erased when I tab away from the field and it remains blank.

I've shown "Events with Scripts" and I only see my basic script:

topmostSubform.Page1.COST_1::calculate - (FormCalc, client)
IF (BUY_TYPE_1 =="CPM") then
UNIT_COST_1.rawValue*QUANTITY_1.rawValue/1000
elseif (BUY_TYPE_1 =="CPC") then
UNIT_COST_1.rawValue*QUANTITY_1.rawValue
else ""
endif

Can't see what's causing the manual entry to over ride.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Do a test, create a blank form and add a couple of fields. Make one a calcuated field that can be overridden. Make the caculation something very simple such as copying the value of the other field.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

ddalben
Registered: Jun 22 2010
Posts: 3
In the end I scrapped it all, pulled out my Dummies guide to Javascript and wrote the script in JS. Works fine now. Thanks for taking the time to help.