Copy link to clipboard
Copied
I am able to make the current date and time populate a field. However, I would like for it to allow the user to enter a date and time, and if nothing entered then default to the current date and time. Is this possible?
Current code I am using is this:
this.getField("CompTime").value = util.printd("mm/dd/yyyy HH:MM", new Date());
This gives me current date and time, but it cannot be changed.
It would be something outside of the form. I don't have any way to tie something automated to the form to trigger the date/time to be entered other than a mouse click by the operator on the field itself.
As an alternate:
Would there be a way to add a button at each time/date field that when pressed would enter the current time/date, otherwise the operator could click in the field and manually enter the time/date?
Copy link to clipboard
Copied
Yes, that's possible. Your script is correct, where is it being used? In what script? And how? Do you want the date to remain unchanged after it is set to current?
Copy link to clipboard
Copied
The script is in the form field "CompTime" under actions. I would like the time to be able to be manually changed, if needed.
Copy link to clipboard
Copied
So right now you have it setup so that the current time is populated when the user clicks on the Field? You're current script forces the field value to change and it cannot be overridden. This isn't going to work for the final script, which needs to keep the field the same when it contains a date value.
So to move forward, the first thing you need to do is to figure out the exact behavior of the field. Basically, what causes the field to be set to the current date? For example, it could be when the form is loaded, or anytime the field is blank. This is the starting point, then we can figure out how this can be safely overridden for manual entry.
Copy link to clipboard
Copied
Thank you Thom.
What I am building is a form that will be filled out during a manufacturing process. There will be several places that there are start and end times for different steps taking place that the operator needs to enter. The only reason that the operator would need to change the date/time would be if they forgot to enter the information at the time it was required, and had to go back and fill the time in later.
Copy link to clipboard
Copied
What is the initial trigger that causes the date to be entered in the first place?
Copy link to clipboard
Copied
It would be something outside of the form. I don't have any way to tie something automated to the form to trigger the date/time to be entered other than a mouse click by the operator on the field itself.
As an alternate:
Would there be a way to add a button at each time/date field that when pressed would enter the current time/date, otherwise the operator could click in the field and manually enter the time/date?
Copy link to clipboard
Copied
Yes, this would be a good way to do it. You could also have a button for starting the entire process that would make sure the form is cleared was well as pre-filling fields like the current date. In either case the script you are already using works fine as a button script.
and you don't need anything special to allow the user to edit the field.
Copy link to clipboard
Copied
Thank you Thom, that worked.
Copy link to clipboard
Copied
Absolutely! It's definitely possible to create a field that allows users to enter a date and time, while still defaulting to the current date and time if nothing is entered. Here's how you can achieve that:
Utilize Conditional Logic: You can leverage conditional statements within your code to check if the user has entered any value in the field. If the field is empty, assign the current date and time using your existing code util.printd("mm/dd/yyyy HH:MM", new Date()). If the user enters a value, it will overwrite the default.
Event Listeners: Another approach involves setting up an event listener on the field. This listener would trigger a function whenever the user interacts with the field (e.g., typing or clicking away). The function would then check if the field is empty and populate it with the current date and time if needed.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now