Copy link to clipboard
Copied
Hi, I have a text field called “customerBName” which by default is always visible and another two fields called “customerBAddress“ & “customerBTel” which by default are hidden.
I need a script for the On Focus event on
”customerBName” which will do the following:
When the user clicks (or tabs) into “customerBName” then the fields “customerBAddress” & “customerBTel” become visible(but not printable).
If the user then enters data in ”customerBName” and subsequently tabs out then the other two fields remain visible(but not printable).
However, if no data was entered in “customerBName and the user tabs out then the other two fields revert back to their original hidden state.
Copy link to clipboard
Copied
On Focus script:
this.getField("customerBAddress").display = display.noPrint;
this.getField("customerBTel").display = display.noPrint;
On Blur script:
if (event.target.value=="") {
this.getField("customerBAddress").display = display.hidden;
this.getField("customerBTel").display = display.hidden;
} else {
this.getField("customerBAddress").display = display.noPrint;
this.getField("customerBTel").display = display.noPrint;
}
Copy link to clipboard
Copied
The code works pretty much the way it's supposed to, however, if no data is entered in customerName2 and I tab over it doesn't continue on to the next visible field in the tab order. It restarts the tab order from the beginning of the document.
Copy link to clipboard
Copied
Sorry, I meant customerBName
Copy link to clipboard
Copied
Yeah, it seems to cause some confusion in the tab order... This solution worked for me, though.
In the first part of the On Blur script add the following command:
this.getField("Name of next field in the tab order").setFocus();
Copy link to clipboard
Copied
Is there any way to differentiate an On Blur event between a user tabbing to the next field and a user clicking with the mouse in to another field?
Because the tabbing order is obviously meant to be set if the user is using the tab button to tab over in order to make it easier to fill out a form. However, the user should still be able to click in to any field with the mouse if they so choose.
This script forces the focus on the next field in the tab order - even though the user clicks with the mouse in to a different field that is not in the tab order it still puts the focus back in to the field that your forcing the focus on.
Copy link to clipboard
Copied
No, it's the same event.
Copy link to clipboard
Copied
Well, there is the "event.commitKey" property Try it out.
Here's the AcroJS Ref entry: Acrobat DC SDK Documentation
Copy link to clipboard
Copied
The event.commitKey in general only seems to work when used in the Format tab. It doesn't work for some reason when it's in the actions tab. And when I placed the rest of the code in the format tab nothing worked not even the action of the fields becoming visible and hidden. It doesn't seem like it'll work unless I'm not doing it right....
Copy link to clipboard
Copied
The trick to using this value in the OnBlur event is to capture it when it is valid and store is somewhere, such as a document variable. I haven't done any testing so I'm unclear on the specifics of how it is used. But this property is obviously specific to the commit process so I suspect that it's value is valid in the keystroke event when event.willCommit is true.
so this could be the keystroke script:
if(event.willCommit) this.commitKeyValue = event.comitKey;
Copy link to clipboard
Copied
See this chart to see when each even triggers. It'll help you decide exactly where your script needs to go. Also, not all even properties are present in the event object with each event.