Sort and Bold Catalog Item Select Box Results

Charles1
Tera Contributor

Hi all,

 

I have a Catalog Item with a Select Box that is being populated from a Catalog Client Script with and API call that returns JSON.  The Select Box is displaying a combination of 2 fields from the API call.  I would like to have 1 of the fields be Bold.  I have tried numerous way to get the 1 field to display Bold but have not had any success.  Any suggestions?

 

Also, I would like to have the Select Box results display alphabetically. Is the a way to sort?

 

Here is the function from the Catalog Client Script that populates the Select Box:

 

function getResponse(response){
    var answer = response.responseXML.documentElement.getAttribute("answer");
    try{
        if((answer != '') && (answer != 'undefined')){
            var array = answer.toString().split(',');
            var optNames = [];
            var optIds = [];
            var optDescriptions = [];
            for(var z = 0; z < array.length; z++){
                var splits = array[z];
                var desc3 = splits.toString().split("::");
                var id = desc3[0].toString();
                var name = desc3[1].toString();
                var guid = desc3[3];
                var description = '• ' + desc3[2].replaceAll('-usplit-', '\n• ');
                description = description.replaceAll('-insertcomma-', ',');
                g_form.addOption('access_model_list', id, name + "[ " + description + "  ]" );
            }
        } else {
            g_form.clearOptions('access_model_list');
        }
 
This is the resulting Select Box:
Charles1_0-1710341140235.png

Thanks in advance for any suggestions

 
1 REPLY 1

Brad Bowman
Kilo Patron
Kilo Patron

There is not a way to display rich text like bold, italics,... in the select box choices.  The sort order is determined by the order the choices are added via addOption if you aren't supplying the fourth parameter which is the index.  In this case, you would want to sort the array before it is returned to the client, or build a new object array of id:name[description], then sort that outside of the existing for loop before using addOption.