While most of the enum or dropdown fields in Sugar are typically populated by a static list of options, sometimes you’ll want to get the list of options straight from the database. Let’s look at an example from the app to see how we can do this.
The Bugs module has a field named ‘found_in_release’, with the field definition as follows:
The parameter that is important here is ‘function’, where the value of this is a function to call to get the options to display in the UI for this field. The function shouldn’t require any arguments, and should return an associative array with the key as the database value and the value as the display value. For this example, the function looks like this:
You can use this same pattern anywhere you want to create a database driven dropdown.