In search of JavaScript to format date field in browser
Copy link to clipboard
Copied
It is a known issue that the date picker does not work in web browsers. I accept that. I have seen the other posts, including:
How do you make Date Drop downs available to use o... - Adobe Support Community - 12758876
Calendar in date field is not working in Chrome - Adobe Support Community - 13173706
If I just enter numbers into the date field in a browser, such as “05152023”, it converts it to current date (“08/14/2023”). If I enter “02122023”, it converts to “02/22/2023” (yes, it changed the day value). If I enter a formatted date, such as “05/15/2023”, it’s ok.
So, my question – is there a way to use JavaScript to intercept the date and add formatting, before it gets changed by the browser?
Please note, I am already using the following to convert the datepicker to mm/dd/yyyy, as the default date format in our system is d.m.yyyy (which is probably another reason the date is getting messed up, but I can’t fix that):
var DateOfSignature = this.getField("DocumentSignature_DateOfSignature");
var requiredFormat = "mm/dd/yyyy";
DateOfSignature.setAction("Format", "AFDate_FormatEx(\""+requiredFormat+"\")");
DateOfSignature.setAction("Keystroke", "AFDate_KeystrokeEx(\""+requiredFormat+"\")");
I think I need a way to tell if I am using Adobe or a web browser to prevent the code above from firing, but I have not found a way to do that yet, either. Please note, the PDF is being created in Inspire Designer, so that adds its own layer of complexity to the situation.
Thanks.
Copy link to clipboard
Copied
If it doesn't work in a browser (which is not surprising) there's not much you can do about it.
You can show a message instructing the user to open the file in Reader, and then use a script to hide it if the file is opened in Reader (or Acrobat), but that's just about it.
Copy link to clipboard
Copied
Thanks. I read the article Forcer l'utilisation d'un PDF avec Acrobat Reader • abracadabraPDF (translated), but, as mentioned, I don't know how to tell if the user is already in Adobe or not. And I don't want to have to force the users to open in Adobe.
I was hoping for scripting advice, as some of the scripting we are doing does work in some of the browsers. I was able to find the 'setAction("Format", "AFDate_FormatEx..' code in the Community (thank you) which is not available in "JavaScript for Acrobat API Reference". So I was hoping someone might have already tried to tackle this issue with some success.
Copy link to clipboard
Copied
The companies that develop browsers, or any other app that displays a PDF are free to implement their tool any way they want. It really is the wild west. Small companies often just omit features like JavaScript, stamps, and forms. But even big ones like MS and Apple who can afford to do it right, seem to deliberately screw up feature implementation because they can. There is no way for the document to know if it is opened in a friendly compliant application, a cut-down minimal implementation, or an evil non-compliant application.
So what you need to do is tell your users to use a compliant application. Otherwise there is no guarentee, and there is nothing you can do about it.
Use the Acrobat JavaScript Reference early and often

