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

sort data when added via an ADD button to pdf form

Community Beginner ,
Mar 08, 2016 Mar 08, 2016

I have a pdf form with a drop down. It is populated with sorted data. The form also have a button for user to add data if their desired data is not already populated. The problem is the added data do not get sorted, they just get added to the bottom of the drop down list. However, if go to edit form, the added data appears sorted in drop down.

the script I am using on button to add individual data to the drop down is

var f = this.getField("FullName");

var ni = f.numItems;

f.insertItemAt(f.value, "", ni);

Any help apprecited!

TOPICS
Acrobat SDK and JavaScript , Windows
551
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 ,
Mar 08, 2016 Mar 08, 2016

You should enable the option to sort the options automatically under the field's Properties (Options tab).

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
LEGEND ,
Mar 08, 2016 Mar 08, 2016

You can get all of the existing items in the dropdown into array, add the new item to the array, sort the array using the array.sort method, and repopulate the dropdown using the setItems field method. Try67's approach doesn't cause the items to be automatically sorted when the items are set programmatically.

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 ,
Mar 09, 2016 Mar 09, 2016

Thank you George. But I want the user be able to do this on the go! Is there anyway to change the script for the button that is also fast enough to do this?

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
LEGEND ,
Mar 09, 2016 Mar 09, 2016
LATEST

That's what I figured and you can do all of what I outlined with a script. You can use the getItemAt method in a loop to get the existing items. Give it a try yourself and post your script if you get stuck.

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