Select field in custom module
I have a simple custom module named "Supports" and it's working fine. I have a field called "Category" and in the admin, I want to be able to change it from an input text field to a select field so I can limit what the user enters when they create a new Support. Can anyone tell me how to implement this or point me in the right direction?
Comments
I think you can call the form function in your "Support" module to overwrite it.
function form_fields($values = array()) { $fields = parent::form_fields($values); $options = array('1'=>'Option1','2'=>'Option2'); //this should supply list of options $fields['Category'] = array('label' => 'Category', 'type' => 'select', 'options' => $options, 'value' => '', 'mode' => 'single'); return $fields; }
you can check out the sample code on category module.
Where is the category module you refer to located, so I can see more sample code?
'Profile & Settings'=>'Profile & Settings',
When it outputted the html for the select, it converted ampersand in the value of that option to '&'. I changed the option to 'and' instead. That fixed it.
'Profile & Settings'=>'Profile & Settings',
in the select list, it gets converted to :
<option value="Profile & Settings" label="Profile & Settings">Profile & Settings</option>
and this value gets inserted into the database:
Profile & Settings
When I return to edit the entry again, it doesn't have Profile & Settings selected. Instead, it defaults back to the first option in the select list. In fact, the select list goes back to the first option as soon as I click save since the page reloads.