Copy link to clipboard
Copied
I'm not really sure if I am asking this correctly. I know very little about javascript. I created a pdf form that is used by officers to track daily tasks in relation to a certain project. There are several lines- each line a different task or action.
Example:
Each row has a start and stop time.
I know how to create a button that will put a timestamp in a field. There are 24 rows in this sheet, so to do it the way I know how - would be 48 buttons (one button per row for start, one button per row for stop). That's a lot of buttons and a lot of real estate on my form, even if the buttons are tiny.
Is there a way to have a button that timestamps the next empty time field? I am not sure that makes sense, but have like 1 button that when clicked - puts the current time in the next "not null" time field?
Thank you.
Yes, it's possible. Let's say the fields are called Text1, Text2, etc. up to Text48.
You can use this code to do it:
for (var i=1; i<=48; i++) {
var f = this.getField("Text"+i);
if (f.valueAsString=="") {
f.value = util.printd("HH:MM", new Date());
break;
}
}
Copy link to clipboard
Copied
Yes, it's possible. Let's say the fields are called Text1, Text2, etc. up to Text48.
You can use this code to do it:
for (var i=1; i<=48; i++) {
var f = this.getField("Text"+i);
if (f.valueAsString=="") {
f.value = util.printd("HH:MM", new Date());
break;
}
}
Copy link to clipboard
Copied
That's awesome! Thank you so much!
I actually made 2 buttons and replaced by headers "start" and "stop" with buttons "start" and "stop" and named my fields start1, start2, etc and stop1, stop2, etc. and adjusted the count to 24 since each button is only responsible for half. That just saved me and my team a lot of time trying to time in times. Thank you!
Copy link to clipboard
Copied
That's a good approach!
Copy link to clipboard
Copied
Follow up question since you made that so easy ... What would the script look like for a button that then clears all of the timestamps at once? At the end of each shift they will print the log, and then will need to clear all of the fields.
Thanks! I did try to research this myself and tried several things - that didn't work at all.
Copy link to clipboard
Copied
Ok, pretend I didn't ask that. I was so stuck in javascript mode I completely forgot adobe already has a button for that.
DOH!!
Copy link to clipboard
Copied
Yes, but if you don't want to tick all the fields in the list you can do it with this code:
var fieldsToReset = [];
for (var i=1; i<=24; i++) {
fieldsToReset.push("start"+i);
fieldsToReset.push("stop"+i);
}
this.resetForm(fieldsToReset);
Copy link to clipboard
Copied
That works so much better! I have some header info that needs reset too (date, detail, etc.) but some that is static to each person's copy (name, badge number, etc). So I was able to add in the other fields that need reset to the code you gave me, and leave the others alone.
You have been a life saver!
Copy link to clipboard
Copied
I hope I don't push it too far asking another question.
If you look at my original snapshot, I have 2 columns - Activity and Location. The fields under them are ActivityRow1, ActivityRow2, and so on - and LocationRow1, etc.
What I would like to do - is to have a combo box in the header field for each and define a list in each. Example for activities -- IL, OL, C1,C2, C3, C4.
So my goal is to select a value from the drop down and have that value populate the next empty field in the column.
I've been able to create combobox's and define the lists - but every example of the scripting I have found hasn't worked.
Thanks!
Copy link to clipboard
Copied
Use this code as the custom validation script of the drop-down:
for (var i=1; i<=24; i++) {
var f = this.getField("Activity"+i);
if (f.valueAsString=="") {
f.value = event.value;
break;
}
}
Make sure to tick the option to commit the selected value immediately, under the field's Properties, Options tab.
Copy link to clipboard
Copied
Got it!
Is there also a way to make it revert to a value (or display a value) after you click? Like now, if I select C3, it puts that in the next empty field - but then it still says C3 in the text of the combo box too. If possible - I'd like it to say "Activity" after the selection is made. I am using the buttons and boxes over top of the column headers so I'd like it to display what the column header would display as default.
Thank you so much for all of your help!
Copy link to clipboard
Copied
If "Activity" is the default value add this at the end of the code:
event.rc = false;
Copy link to clipboard
Copied
That actually took me longer to figure out/implement than the rest did. I probably should have mentioned that my department is too cheap for real adobe - we use Foxit Phantom. I take it from other websites where I tried reading to learn this, that adobe says the first item in the list is the default value (or at least that's how I understood it).
Well that didn't work with Foxit. I finally stumbled on the right recipe. Foxit is more like "whatever list item you leave highlighted when you close the properties box is your default value."
Sir you have been a tremendous help to me and I can not thank you enough. This is going to allow officers the ability to fill out their daily logs a LOT quicker and that means more time with their eyes on the world rather than staring at their computers.
Copy link to clipboard
Copied
In that case you can try something like this:
event.value = "Activity";
Or even:
event.value = event.target.defaultValue;
Glad to hear I was helpful to you!