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!
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
...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.
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();
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.
Copy link to clipboard
Copied
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.