Dropdown Help!!!

Community Beginner ,
Jan 30, 2019 Jan 30, 2019

Copy link to clipboard

Copied

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

Views

186

Likes

translate

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

Most Valuable Participant , 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;

Likes

translate

Translate

Translate
Most Valuable Participant ,
Jan 30, 2019 Jan 30, 2019

Copy link to clipboard

Copied

Where did you place this code?

Likes

translate

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

Copy link to clipboard

Copied

Under the Calculate tab in the Custom calculation script.

Likes

translate

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
Most Valuable Participant ,
Jan 30, 2019 Jan 30, 2019

Copy link to clipboard

Copied

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.

Likes

translate

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

Copy link to clipboard

Copied

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? 

Likes

translate

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
Most Valuable Participant ,
Jan 30, 2019 Jan 30, 2019

Copy link to clipboard

Copied

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;

Likes

translate

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

Copy link to clipboard

Copied

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?

Likes

translate

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
Most Valuable Participant ,
Jan 31, 2019 Jan 31, 2019

Copy link to clipboard

Copied

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?

Likes

translate

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

Copy link to clipboard

Copied

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!

Likes

translate

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
Most Valuable Participant ,
Jan 31, 2019 Jan 31, 2019

Copy link to clipboard

Copied

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

var oldValue = event.target.value;

To:

var oldValue = event.value;

Likes

translate

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

Copy link to clipboard

Copied

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.

Likes

translate

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
Most Valuable Participant ,
Jan 31, 2019 Jan 31, 2019

Copy link to clipboard

Copied

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)?

Likes

translate

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

Copy link to clipboard

Copied

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

Likes

translate

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