Dropdown field always sorted alphabetically

Postdate: April 13 2012
Category: Created Modules
Applies to: 2.0x

Dropdown fields are sorted alphabetically by default. But what if you want to sort by ID or Alias? It's easy to change... sort of.


Look for the fileĀ class.ctlmm_field.php in the folder /MODULENAME/classes/
Open it and search for the function:
public function getOptionsArray($db=false)..

The trick lies in the this line:

$dbresult = $db->Execute("SELECT `$label_field` thelabel, 
`$value_field` thevalue FROM $tablename ORDER BY `$label_field`");

Change $label_ to $value_ and the sortorder is changed to the value-field. Most of the time this would be ID or the alias, but it depends on what you have specified during the creation process of your module with the dropdownfields option value.

Note:

You should always backup your files prior to editing!