Skip to main content
Participating Frequently
March 8, 2016
Question

sort data when added via an ADD button to pdf form

  • March 8, 2016
  • 2 replies
  • 609 views

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!

This topic has been closed for replies.

2 replies

Inspiring
March 8, 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.

Participating Frequently
March 9, 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?

Inspiring
March 9, 2016

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.

try67
Community Expert
Community Expert
March 8, 2016

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