13 Replies Latest reply: Jul 29, 2012 3:40 PM by George_Johnson RSS

    Bug: Custom Keystroke Script.

    chad Snelson Community Member

      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?

        • 1. Re: Bug: Custom Keystroke Script.
          GKaiseril ACP/MVPs

          You might try the updated

           

          AFDate_FormatEx()

           

          And a format string.

          • 2. Re: Bug: Custom Keystroke Script.
            chad Snelson Community Member

            I'm not sure what you mean could you give me an example of how I would impliment what you suggested with the two scripts I mentioned in my question?  Did you try what I described in my question with similar results?

            • 3. Re: Bug: Custom Keystroke Script.
              GKaiseril ACP/MVPs

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

              • 4. Re: Bug: Custom Keystroke Script.
                chad Snelson Community Member

                I'm really confused, I don't know anything about codeing. After reading through that link I still don't really understand your suggestion.

                • 5. Re: Bug: Custom Keystroke Script.
                  GKaiseril ACP/MVPs

                  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?

                  • 6. Re: Bug: Custom Keystroke Script.
                    chad Snelson Community Member

                    Thank you for the reply.

                     

                    Would you mind just making a text field and giving it a tooltip name.

                     

                    Then add a 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)

                    }

                     

                    after adding the custom format script.

                     

                    Add a custom keystroke script:

                    //Keystroke

                    AFDate_Keystroke(5)

                     

                    and let me know what happens for you?

                    • 7. Re: Bug: Custom Keystroke Script.
                      GKaiseril ACP/MVPs

                      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.

                      • 8. Re: Bug: Custom Keystroke Script.
                        chad Snelson Community Member

                        No this is the issue maybe with screenshots it will make more sense:

                         

                        So I enter the Custom Format Script:

                        script1.PNG

                         

                        Everything is fine and dandy:

                        script2.PNG

                         

                        But when I enter the Custom Keystroke Script:

                        script3.PNG

                         

                        My Custom Formating is still there but I can't edit it because it's changed it to date instead of Custom:

                        script4.PNG

                         

                        Does that make more sense?

                        • 9. Re: Bug: Custom Keystroke Script.
                          GKaiseril ACP/MVPs

                          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.

                          • 10. Re: Bug: Custom Keystroke Script.
                            chad Snelson Community Member

                            What I'm trying to acccomplish is to have the tooltip name of a field displayed in the field by default but not print unless someone has added text to it.

                             

                            The text that I want to be entered is a date format so I want it to be validated and put in a standard format dd-MMM-YY.

                             

                            But the bug I was reporting is that when you put in the Custom Keystroke Script it changes it from custom validating to standard date formating but still has the first Custom Formating Script working in the background but you can't see the script or edit it.

                             

                            Also just noticed that when it switches to the standard date format it selects m/d/yy but when you enter text it isn't formated that way.

                             

                            I think we are confused about what the other person is trying to explain.

                            • 11. Re: Bug: Custom Keystroke Script.
                              George_Johnson ACP/MVPs

                              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.

                              • 12. Re: Bug: Custom Keystroke Script.
                                chad Snelson Community Member

                                George, you're a saint! Thank you so much for replying and understanding what I was trying to say.

                                 

                                As I've said before on other thread that you've helped me with, I don't know anything about scripting and kinda just hash together what I use.

                                 

                                I don't know what document level scripting is or how to use it.  Do you have any suggested reading that would explain a little bit more about it?

                                 

                                Also how would I accomplish what I'm trying to accomplish with a document level script?

                                • 13. Re: Bug: Custom Keystroke Script.
                                  George_Johnson ACP/MVPs

                                  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.