Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
You should enable the option to sort the options automatically under the field's Properties (Options tab).
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now