Making field visible based on OnFocus event of another field

Community Beginner ,
Apr 14, 2018

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.

TOPICS
Acrobat SDK and JavaScript

Views

298

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

Making field visible based on OnFocus event of another field

Community Beginner ,
Apr 14, 2018

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.

TOPICS
Acrobat SDK and JavaScript

Views

299

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
Apr 14, 2018 0
Most Valuable Participant ,
Apr 15, 2018

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;

}

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
Reply
Loading...
Apr 15, 2018 0
Community Beginner ,
Apr 15, 2018

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.

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
Reply
Loading...
Apr 15, 2018 1
Community Beginner ,
Apr 15, 2018

Copy link to clipboard

Copied

Sorry, I meant customerBName

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
Reply
Loading...
Apr 15, 2018 0
Most Valuable Participant ,
Apr 15, 2018

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();

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
Reply
Loading...
Apr 15, 2018 0
Community Beginner ,
Apr 15, 2018

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.

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
Reply
Loading...
Apr 15, 2018 0
Most Valuable Participant ,
Apr 16, 2018

Copy link to clipboard

Copied

No, it's the same event.

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
Reply
Loading...
Apr 16, 2018 0
Adobe Community Professional ,
Apr 16, 2018

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

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
Reply
Loading...
Apr 16, 2018 0
Community Beginner ,
Apr 16, 2018

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....

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
Reply
Loading...
Apr 16, 2018 1
Adobe Community Professional ,
Apr 16, 2018

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;

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
Reply
Loading...
Apr 16, 2018 0
Adobe Community Professional ,
Apr 16, 2018

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.

Acrobat DC SDK Documentation

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
Reply
Loading...
Apr 16, 2018 2