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

Is it possible to format a PDF form field with date AND assign the same field a Default Value?

Community Beginner ,
Dec 01, 2020 Dec 01, 2020

Copy link to clipboard

Copied

Specifically, I have a form field that I'd like to be subjected to the date formatting (mm/dd/yyyy). Rather than rely on a tooltip or other means to alert the user to this format, I'd prefer to use the Default Value on the form field (text field properties>options>default value). When I enter the default value I'd prefer, mm/dd/yyyy, it's rejected by the form as the date formatting takes precedence over this label. This makes sense to me, but I do not know another work-around to remedy this scenario. For what it's worth, here is my code from the custom validation field:

if (event.value) {
if (util.scand("mmddyyyy", event.value)==null){
app.alert("Please format date: mm/dd/yyyy.");
event.rc = false;
}
}

Any help would be sincerely appreciated. Thanks!

TOPICS
Acrobat SDK and JavaScript

Views

1.8K

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

correct answers 1 Correct answer

LEGEND , Dec 01, 2020 Dec 01, 2020

I think the best workaround for doing what you describe would be to create a custom Format and Keystroke script that is based on the built-in ones that Acrobat uses to limit the field entry to certain values. The Keystroke script could be the same (e.g., AFDate_Keystroke), but the Format script could be modified so that the string "mm/dd/yyyy" is displayed in the field when the field value is blank. You wouldn't use a Validate script if you use this approach. If you need more help, post again, a

...

Votes

Translate

Translate
LEGEND ,
Dec 01, 2020 Dec 01, 2020

Copy link to clipboard

Copied

I think the best workaround for doing what you describe would be to create a custom Format and Keystroke script that is based on the built-in ones that Acrobat uses to limit the field entry to certain values. The Keystroke script could be the same (e.g., AFDate_Keystroke), but the Format script could be modified so that the string "mm/dd/yyyy" is displayed in the field when the field value is blank. You wouldn't use a Validate script if you use this approach. If you need more help, post again, and we can suggest specific scripts you can use. 

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 ,
Dec 02, 2020 Dec 02, 2020

Copy link to clipboard

Copied

George,

This was exactly the nudge I needed. With this info I was able to track down the answer I needed from another post (by you, lol) which worked perfectly. Should somebody else need this same help, I'll paste George's helpful answer below. Thanks again!

 

"Add the following functions to a document-level Javascript:"

function dateFormat() {

var sFormat = "mm/dd/yyyy";

if (!event.value) {
event.value = sFormat;
event.target.display = display.noPrint;
} else {
AFDate_FormatEx(sFormat);
event.target.display = display.visible;
}

}

function dateKeystroke() {

AFDate_KeystrokeEx("mm/dd/yyyy");

}

 

"Call the first function in a custom Format script and the second in a custom Keystroke script, something like:"

// Custom Format script
dateFormat();


// Custom Keystroke script
dateKeystroke();

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 ,
Aug 26, 2021 Aug 26, 2021

Copy link to clipboard

Copied

When utilizing this custom document level javascript, do I create separate scripts for each part?

Example: add new document level script for the custom dateFormat, ok save, done. Then add another one for the custom keystroke? Or can they be in the same function.. if that makes sense. 

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 ,
Aug 26, 2021 Aug 26, 2021

Copy link to clipboard

Copied

LATEST

They should not be in the same function because they are two separate things, but both functions can be under a single doc-level script.

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