Avatar

Correct answer by
Level 10

Hi Praveen,

You could add the items to the drop down list in a sorted order, which would involve loading the items into an array, sorting them and then loading them into the drop down list.  So this would be in the click event of the add button.

// Create an array to hold all out drop down list items, the array contains objects with a "displayItem" and "value" property

var dropDownItems = [];

// Add the new one

dropDownItems.push({displayItem: ItemName.rawValue, value: BoundValue.rawValue});

// Add the existing ones

for (var i = 0; i < DropDownList1.length; i++)

{

    dropDownItems.push({displayItem: DropDownList1.getDisplayItem(i), value: DropDownList1.getSaveItem(i)})

}

// Sort ascending order of the display text

dropDownItems.sort(

    function(a, b)

    {

        if (a.displayItem < b.displayItem) return -1;

        if (a.displayItem > b.displayItem) return 1;

        return 0;

    });

// clear all items

DropDownList1.clearItems();

// load up the sorted items

for (var i = 0; i < dropDownItems.length; i++)

{

    var dropDownItem = dropDownItems[i];

    DropDownList1.addItem(dropDownItem.displayItem, dropDownItem.value);

}

// clear source fields

ItemName.rawValue = null;

BoundValue.rawValue = null;

I've added a "Add Sorted" button to my sample, https://workspaces.acrobat.com/?d=OwysfJa-Q3HhPtFlgRb62g

Regards

Bruce

View solution in original post