Sorting Option values from a Metadata Selection Field

I have a Search page where I have selected a Metadata Selection Field as the Asset Metadata Field type to be used as the Search Field which can then be browsed from a dropdown menu. A list of results is then presented when a field is selected.

 

The problem I have is that the dropdown menu presents the Metadata Selection Field Option values in the order they were created in (and new values will be added over time), so I'd like to be able to sort them alphabetically to make it easier for users to scroll through and make a selection, but I haven't been able to figure out how to do this.

 

Does anyone have any suggestions for how to sort option values from a Metadata Selection Field?

Think you'd probably have to resort to sorting in Javascript on the front end, if you want to use the natively generated control. We tend to end up going for text metadata fields, then putting a select list over that using the form body content - it means the metadata field doesn't contain all the options, but means we can put what we like in the select list, and add new options or modify existing ones without having to regenerate the metadata files.

A quick Google and there are some nice js/jQuery options to do this:

 

 

function NASort(a, b) {    
    if (a.innerHTML == 'NA') {
        return 1;   
    }
    else if (b.innerHTML == 'NA') {
        return -1;   
    }       
    return (a.innerHTML > b.innerHTML) ? 1 : -1;
};

$(‘select option’).sort(NASort).appendTo(‘select’);
 

 

Demo : http://jsfiddle.net/4bvVz