Copy link to clipboard
Copied
I am having problems auto-populating individual day, month and year fields of my form when the form is being opened.
When I open the form, I am getting these errors:
"Invalid date/time: Please ensure that the date/time exists. [Day] should match format d"
"Invalid date/time: Please ensure that the date/time exists. [Month] should match format mmm"
I have in my forms, fields named "Day", "Month", and "Year". They are all of a date format, with a custom format for "Day" being d, and for "Month" mmm and for "Year" yyyy. All three are set as "Read Only" and "Required"
I put this JavaScript event in the ACTIONS tab of the PAGE PROPERTIES of the page with the fields I am trying to populate.
var fd = this.getField("Day");
fd.value = util.printd("d", new Date());
var fm = this.getField("Month");
fm.value = util.printd("mmm", new Date());
var fy = this.getField("Year");
fy.value = util.printd("yyyy", new Date());
The properties in the EVENTS tab are:
Select trigger: Page Open
Select action: Run a JavaScript
I save the document, and when I run, I get the errors. When I go back to the Page Properties to check the event, the select action had changed to "Execute a menu item". I can't seem to keep "Run a JavaScript" as the preferred parameter.
The action box does reflect run a JS on page open.
Where am I going wrong?
Copy link to clipboard
Copied
Set the Format setting of these fields to None.
Copy link to clipboard
Copied
It should show "Mar"... Do you use a different locale on your computer?
And the year should work fine, too. Are you sure there aren't any errors in your code? Check the JS Console (Ctrl+J).
Copy link to clipboard
Copied
Set the Format setting of these fields to None.
Copy link to clipboard
Copied
Thank you try67!
Almost there, but still a couple problems.
I am wishing my month to be expressed as "Mar" for March as an example. What I am getting now is simply "Ma"
The year, expecting "2023", is empty.
Copy link to clipboard
Copied
It should show "Mar"... Do you use a different locale on your computer?
And the year should work fine, too. Are you sure there aren't any errors in your code? Check the JS Console (Ctrl+J).
Copy link to clipboard
Copied
Awesome! Got it working.
Turns out I had some residual settings from when I was manually entering the data into these fields. I had a limit of two characters set in the options that restricted the values.
The JS Console revealed at error in my JS ... one of my variables was inconsistent.
Thank you once again!