Skip to main content
Participating Frequently
March 21, 2019
Answered

Date format in forms

  • March 21, 2019
  • 1 reply
  • 7629 views

I would like to be able to allow the user filling out the form to enter a date as either dd/mmm/yyyy or only mmm/yyyy.  The exact date may not always be known, so an estimation is acceptable (but it needs to be known as an estimated date).

I am pretty new to Acrobat & Javascript, so I have tried adding a custom format  for the text field by using a known script posted in the forum for 2 functions: the field's custom Format script and the custom keystroke script. I added them as document level JavaScript functions and called them from the fields custom format boxes.  But when I closed the 2nd edit box, it switches to date format and does not seem to acknowledge the custom format. Can you help with both issues? Thanks.

[Title shortened for brevity by moderator. Was:

"I am creating an acrobat fillable form. How can I provide a custom format for dates so that it can accept and fill 2 types of dates. I would like to accept and fill in the format dd/mmm/yyyy  or if the exact data is not known, the format mmm/yyyy will be "

This topic has been closed for replies.
Correct answer try67

Can you tell me how I would change this to allow for the 2 dates dd-mmm-yyyy and mmm-yyyy? Is it as simple as the following?

  1. if (newValue!="" && newValue!="mmm-yyyy") { 
  2.     if (util.scand("dd-mmm-yyyy", newValue)==null) { 
  3.         app.alert("Date field may only contain either a date in dd-mmm-yyyy format, OR mmm-yyyy", 1); 
  4.         event.rc = false
  5.     } 

No, it's not that simple, because the second pattern isn't a real date pattern.

Try this:

var newValue = event.value;

if (newValue!="") {

    if (util.scand("dd-mmm-yyyy", newValue)==null && util.scand("dd-mmm-yyyy", "01-"+newValue)==null) {

        app.alert("Date field may only contain either a date in dd-mmm-yyyy format or mmm-yyyy.", 1);

        event.rc = false;

    }

}

1 reply

try67
Community Expert
Community Expert
March 21, 2019

The problem is that "mmm/yyyy" is not a valid date string (since it doesn't specify a specific date) so that means you can't use the built-in commands that do it. You'll need to write a custom-made validation script that checks the format of the input and validates it against those two patterns.

AnneMAAuthor
Participating Frequently
March 22, 2019

Can you tell me if I am doing something incorrectly as I am trying to learn how to use the custom format option.  I am trying to add a custom script to test out the ability of using a custom script, so I found a script that was supposed to work in the forum.Date field that you can also put N/A into

However, there seems to be a bug.  I was able to create the document javascript for the 2 functions:

Then I added the functions to custom format script and custom keystroke script:

But when I hit ok after this it jumps to the date format and does not accept the custom format

can you help?  Thanks

try67
Community Expert
Community Expert
March 22, 2019

When you use the string "AF" in your code it reverts to one of the built-in options, or removes the code entirely. Try giving it a different name.