Skip navigation
Currently Being Moderated

Bug: Custom Keystroke Script.

Jul 25, 2012 2:31 PM

Tags: #acrobat #script #text #javascript #forms #acrobat_x #acrobat_x_pro #acrobat_forms #acrobat_10_pro

Hello everyone,

 

I have the following for Custom Format Script:

// Custom format script for text field

if (!event.value) {

    event.value = event.target.userName;

    event.target.display = display.noPrint;

} else {

    event.target.display = display.visible;

    AFDate_Format(5)

}

 

and that works all fine and dandy but when I add the following to the Custom Keystroke Script:

//Keystroke

AFDate_Keystroke(5)

 

The menu for the custom format goes away and just shows me the date category.

 

The Custom Format Script still works and functions even though it isn't displayed or editable.

 

Any ideas on what to do to fix it?

 
Replies
  • Currently Being Moderated
    Jul 25, 2012 2:53 PM   in reply to chad Snelson

    You might try the updated

     

    AFDate_FormatEx()

     

    And a format string.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 26, 2012 10:59 AM   in reply to chad Snelson

    If yo look at the util.printd method in the Acrobat JS API Reference, you will find the pic characters for the format string.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 27, 2012 6:50 AM   in reply to chad Snelson

    More basically why do you want to change the script?

     

    Do have any idea of what that script does?

     

    If you use a custom keystroke script, I would expect a custom format script for the display format.

     

    You may have other interactions with that field and without that information it is hard to figure anything out.

     

    You say it does not work. But you do not provide any more information. Are there any error messages? If you are not getting what you expect, what did you expect?

     

    Can you provide a sample of the form?

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 29, 2012 1:29 PM   in reply to chad Snelson

    This is normal when you select an existing format and keystroke like "d-mm-yy" or  a display of "1-Jul-12".

     

    The field property of display changes from "visible does not print" to "visible prints" when a valid date is entered.

     

    I you do not want the field to print I would put the code for printing or not printing in the "Will Print Action" and just chose a date format of "d-mmm-yy" for your example. I personaly would use the 4 digit year for clearity.

     

    Again this method of formatting a field was only used for version 4 and was replaced or updated in version 5 on.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 29, 2012 1:58 PM   in reply to chad Snelson

    You have basically used a different method to set the date format to one of the standard formats than using the "pic" selection. The 5 element of the array of formats for your approach is "d-mm-yy".

     

    As I stated there is also another way to control the displaying of the field by using some scripting in the "Will Print" document action.

     

    Again if you do not understand Acrobat JavaScript and the undocumented or little documented methods, you are better off using the standard supplied interfaces within the program.

     

    You still have not explained what you are trying to accomplish.

     
    |
    Mark as:
  • George Johnson
    11,676 posts
    Aug 11, 2002
    Currently Being Moderated
    Jul 29, 2012 2:40 PM   in reply to chad Snelson

    This could be considered a bug, but the behavior is unlikely to be changed. This is the reason that placing any code that uses any of the built-in keystroke/format functions should be placed in a document-level script and called from the field events, as opposed to directly entering the code in the field events.

     
    |
    Mark as:
  • George Johnson
    11,676 posts
    Aug 11, 2002
    Currently Being Moderated
    Jul 29, 2012 3:40 PM   in reply to chad Snelson

    To add a document-level JavaScript in Acrobat 10, select: Tools > JavaScripts > Document JavaScripts > [Enter a name] > Add

     

    Delete the function skeleton that is provided by default and enter the following two function definitions:

     

    function custom_format_1() {

        // Custom format script for text field

        if (!event.value) {

            event.value = event.target.userName;

            event.target.display = display.noPrint;

        } else {

            event.target.display = display.visible;

            AFDate_FormatEx("dd-mmm-yy");

        }

    }

     

     

    function custom_keystroke_1() {

        // Custom Keystroke script
        AFDate_KeystrokeEx("dd-mmm-yy");

    }

     

     

    Then, enter the following as the field's custom Format script:

     

    custom_format_1();

     

    and the following as the field's custom Keystroke script:

     

    custom_keystroke_1();

     

     

    This calls the functions that you defined in the document-level script, and could be named something more descriptive. You can give the document-level script any name you want, but it should be descriptive as well. For more information, seee the following tutorial:

     

    http://acrobatusers.com/tutorials/js_document_scripts

     

    This tutorial was written before Acrobat 10 and its new user interface, but it should help.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points