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

New Here ,
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!

Adobe Community Professional
Correct answer by George_Johnson | Adobe Community Professional

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. 

TOPICS
Acrobat SDK and JavaScript, PDF forms

Views

44

Likes

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

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

New Here ,
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!

Adobe Community Professional
Correct answer by George_Johnson | Adobe Community Professional

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. 

TOPICS
Acrobat SDK and JavaScript, PDF forms

Views

45

Likes

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
Dec 01, 2020 0
Adobe Community Professional ,
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. 

Likes

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
Reply
Loading...
Dec 01, 2020 0
B.L.D. LATEST
New Here ,
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();

Likes

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
Reply
Loading...
Dec 02, 2020 0