• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Switch fields based on dropdown selection question

Engaged ,
Jan 13, 2021 Jan 13, 2021

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!

TOPICS
General troubleshooting , How to , JavaScript , PDF forms

Views

1.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jan 13, 2021 Jan 13, 2021

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)"]);

Votes

Translate

Translate
Community Expert ,
Jan 13, 2021 Jan 13, 2021

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)"]);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 13, 2021 Jan 13, 2021

Copy link to clipboard

Copied

AHA!  Thank you Try!  Works great now!  Mike and Bill will be very happy lol

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 13, 2021 Jan 13, 2021

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 14, 2021 Jan 14, 2021

Copy link to clipboard

Copied

Where are you getting this message, exactly? Can you share your current file?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 15, 2021 Jan 15, 2021

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 16, 2021 Jan 16, 2021

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;}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 16, 2021 Jan 16, 2021

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;

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 17, 2021 Jan 17, 2021

Copy link to clipboard

Copied

LATEST

Awesome!  Got it!!  That's exactly what I needed!!  Thank you both so much!!  

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 13, 2021 Jan 13, 2021

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 13, 2021 Jan 13, 2021

Copy link to clipboard

Copied

Did you tick 'Allow user to enter custom text' in Employee1Job1-5 properties under options tab?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 13, 2021 Jan 13, 2021

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!!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines