Copy link to clipboard
Copied
I have attached an example with 2 Options of what I would like to be able to do. I would prefer to be able to do Option 1, but I don't know if there's a way to add the custom validation script in the Employee Name text field to switch to multiples Absence Type fields. I would prefer to have the Employee Name text fields repeat, but I can only get Option 2 to work by naming each Employee Name text field individually. I've tried a few things that I thought might work for Option 1, but so far nothing. I left the custom validation script in Option 1, even though it doesn't work. I'm hoping someone has a tip for me. Thank you!
This line of code is wrong:
this.getField("AbsenceTypeJob1Emp1","AbsenceTypeJob2Emp1").setItems([" ","Vacation (Bill)","Sick (Bill)"]);
You have to do it separately for each field, like this:
this.getField("AbsenceTypeJob1Emp1").setItems([" ","Vacation (Bill)","Sick (Bill)"]);
this.getField("AbsenceTypeJob2Emp1").setItems([" ","Vacation (Bill)","Sick (Bill)"]);
Copy link to clipboard
Copied
This line of code is wrong:
this.getField("AbsenceTypeJob1Emp1","AbsenceTypeJob2Emp1").setItems([" ","Vacation (Bill)","Sick (Bill)"]);
You have to do it separately for each field, like this:
this.getField("AbsenceTypeJob1Emp1").setItems([" ","Vacation (Bill)","Sick (Bill)"]);
this.getField("AbsenceTypeJob2Emp1").setItems([" ","Vacation (Bill)","Sick (Bill)"]);
Copy link to clipboard
Copied
AHA! Thank you Try! Works great now! Mike and Bill will be very happy lol
Copy link to clipboard
Copied
Well this is disappointing. I'm getting a new message I've never seen before 'Text is too large to be displayed in this dialogue'. I have approx 50 employees and 10 Jobs so ya, it's big. Not too sure what to do about that, but I'll have to come up with something.
Copy link to clipboard
Copied
Where are you getting this message, exactly? Can you share your current file?
Copy link to clipboard
Copied
Hi Try, sorry for the late reply. I can't share the original file since there are employee names and numbers, but what I did do was created another document which I have added here to my original post and removed the last names and employee numbers. I couldn't enter the JavaScript where I am getting the message so I copied it below. I have a timesheet with a crew of 8 employees and 10 Jobs they could be working on each day. I did enter the JavaScript in the Employee Name text field 'Run custom validation script' with half of the text (Jobs 1-5) and it worked. I could split it (Employee1Job1-5 and Employee1Job6-10), but I want to keep it simple since I do have to maintain the list. If you know of a better way though that would sure make my day!
Copy link to clipboard
Copied
If all 10 field choices are same in each case, you can save some space like this:
switch (event.value) {
case "Derek A":
var fields = ["AbsencePayTypeJob1Emp1","AbsencePayTypeJob2Emp1","AbsencePayTypeJob3Emp1","AbsencePayTypeJob4Emp1","AbsencePayTypeJob5Emp1"];
for (var i in fields) this.getField(fields[i]).setItems([" ","COT","POT","Vacation","Sick","Family Sick","Sick No Pay","Leave No Pay","Compassion Leave","WCB Sick Leave"]);
break;
case "Larry":
var fields = ["AbsencePayTypeJob1Emp1","AbsencePayTypeJob2Emp1","AbsencePayTypeJob3Emp1","AbsencePayTypeJob4Emp1","AbsencePayTypeJob5Emp1"];
for (var i in fields) this.getField(fields[i]).setItems([" ","COT","POT","Vacation","Sick","Family Sick","Sick No Pay","Leave No Pay","Compassion Leave","WCB Sick Leave"]);
break;}
Copy link to clipboard
Copied
Your code is too long for the internal JS editor of Acrobat. You need to use an external editor.
Go to Edit - Preferences - JavaScript and select that option. You can enter "Notepad.exe" as the editor, and then you'll be able to do it.
There are also many ways in which the script can be reduced in size and made more efficient.
For example, use loops to apply the values to the fields, instead of writing them all out, and use a single array for the items in each group, instead of writing them all out each time.
Here's an example:
var items1 = [" ","COT","POT","Vacation","Sick","Family Sick","Sick No Pay","Leave No Pay","Compassion Leave","WCB Sick Leave"];
switch (event.value) {
case "Derek A":
case "Larry":
case "Mike B":
for (var i=1; i<=10; i++) this.getField("AbsencePayTypeJob"+i+"Emp1").setItems(items1);
}
break;
Copy link to clipboard
Copied
Awesome! Got it!! That's exactly what I needed!! Thank you both so much!!
Copy link to clipboard
Copied
Hi Try, I think I came up with something, but I'm stuck and hoping you can help me. I have a dropdown list named 'Employee1Job1-5' and a text field named 'Employee1', where I added the following custom calculation script
event.value = this.getField("Employee1Job1-5").valueAsString;
The text in 'Employee1' displays the same as what has been entered on the Employee1Job1-5 text field which is what I need, but the problem is I need also need the user to be able to be able to enter custom text in the 'Employee1Job1-5' dropdown. I searched and found the following, but it didn't work for me. Is there a simple way I can do this?
if (event.source && event.source.name=="Employee1Job1-5")
event.value = this.getField('Employee1Job1-5').valueAsString;
Thank you!
Copy link to clipboard
Copied
Did you tick 'Allow user to enter custom text' in Employee1Job1-5 properties under options tab?
Copy link to clipboard
Copied
OMG, yes I ticked it off now. I can't believe I missed that, been working too much today. Thank you!!