• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Making field visible based on OnFocus event of another field

Community Beginner ,
Apr 14, 2018 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

708

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
community guidelines
Community Expert ,
Apr 15, 2018 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;

}

Votes

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
community guidelines
Community Beginner ,
Apr 15, 2018 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.

Votes

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
community guidelines
Community Beginner ,
Apr 15, 2018 Apr 15, 2018

Copy link to clipboard

Copied

Sorry, I meant customerBName

Votes

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
community guidelines
Community Expert ,
Apr 15, 2018 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();

Votes

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
community guidelines
Community Beginner ,
Apr 15, 2018 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.

Votes

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
community guidelines
Community Expert ,
Apr 16, 2018 Apr 16, 2018

Copy link to clipboard

Copied

No, it's the same event.

Votes

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
community guidelines
Community Expert ,
Apr 16, 2018 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

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

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
community guidelines
Community Beginner ,
Apr 16, 2018 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....

Votes

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
community guidelines
Community Expert ,
Apr 16, 2018 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;

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

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
community guidelines
Community Expert ,
Apr 16, 2018 Apr 16, 2018

Copy link to clipboard

Copied

LATEST

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

Votes

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
community guidelines