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

Dropdown Help!!!

Community Beginner ,
Jan 30, 2019 Jan 30, 2019

I have created a dropdown that is pulling from 2 hidden fields. Problem is when I select the the second item in the list and tab, it automatically goes back to the first item in the list. I am using the following javascript:

var f1 = getField("PRIMARY_PERSON_LAST_COMMA_SPACE_FIRST_SPACE_MI").valueAsString;

var dropdown = getField('Dropdown1');

var f2 = getField("SHARE_1_SH_PERSON_LINK_1_PERSON_SERIAL_DESCRIPTION").valueAsString;

dropdown.setItems([f1,f2]);

Please help!!!

TOPICS
Acrobat SDK and JavaScript
1.0K
Translate
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 31, 2019 Jan 31, 2019

Move the code to the validation event, and change this line:

var oldValue = event.target.value;

To:

var oldValue = event.value;

Translate
Community Expert ,
Jan 30, 2019 Jan 30, 2019

Where did you place this code?

Translate
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 Beginner ,
Jan 30, 2019 Jan 30, 2019

Under the Calculate tab in the Custom calculation script.

Translate
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 30, 2019 Jan 30, 2019

That means that each time any field in the file is changed the values get re-applied, and the field is reset to the default value (the first one in the list). To overcome that you need to save the current value before applying the list, and then re-apply it afterwards.

You need to take into account the possibility that that value is no longer available, though.

Translate
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 Beginner ,
Jan 30, 2019 Jan 30, 2019

My apologies, but that has totally confused me. I am not JavaScript savvy and just used a script that I found and plugged in the field names in my form. Can you break your explanation down a little more for me? 

Translate
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 30, 2019 Jan 30, 2019

It's easier to write the code than to explain it... Try this code:

var f1 = getField("PRIMARY_PERSON_LAST_COMMA_SPACE_FIRST_SPACE_MI").valueAsString;

var f2 = getField("SHARE_1_SH_PERSON_LINK_1_PERSON_SERIAL_DESCRIPTION").valueAsString;

var oldValue = event.target.value;

var newItems = [f1,f2];

event.target.setItems(newItems);

if (newItems.indexOf(oldValue)!=-1) event.value = oldValue;

Translate
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 Beginner ,
Jan 31, 2019 Jan 31, 2019

Thanks! I tried that code and unfortunately the "PRIMARY_PERSON_LAST_COMMA_SPACE_FIRST_SPACE_MI" field populates and I can click the dropdown and select "SHARE_1_SH_PERSON_LINK_1_PERSON_SERIAL_DESCRIPTION", but it still goes back to "PRIMARY_PERSON_LAST_COMMA_SPACE_FIRST_SPACE_MI" when I tab to the next field. any ideas?

Translate
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 31, 2019 Jan 31, 2019

I don't understand how this issue has to do with your original question... Of course you can tab to the other field. Why wouldn't you?

Translate
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 Beginner ,
Jan 31, 2019 Jan 31, 2019

My apologies for not being clear in my initial post.

This is my dropdown and when I select Paul it defaults back to Abigail when I tab to the next field in my form. I would like it to stay on Paul. I hope this clears things up. Thanks for all your help!

Translate
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 31, 2019 Jan 31, 2019

Move the code to the validation event, and change this line:

var oldValue = event.target.value;

To:

var oldValue = event.value;

Translate
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 Beginner ,
Jan 31, 2019 Jan 31, 2019

I'm not sure what I am doing wrong for I am sure it is user error, but the dropdown is now blank when I moved the code to the validation tab and made the suggested change.

Translate
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 31, 2019 Jan 31, 2019

It worked for me when I tried it... Can you share your file with us (via Dropbox, Google Drive, or even the Share function in Acrobat)?

Translate
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 Beginner ,
Feb 04, 2019 Feb 04, 2019
LATEST

I moved the code to the Actions Tab. Trigger: On Focus, Action: Run JavaScript and got the results I was looking for. Thank you for all your help!!!

Translate
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