Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Data Model Questions

Search Text field with Dropdown. [SOLVED]


4 Posts   1587 Views


23 June 2011 at 10:07pm (Last edited: 23 June 2011 11:10pm), Community Member, 24 Posts


How would I do the above, I have a text field which is an amalgamation of several other fields.

I want to be able to search the TextField with my custom search context with a dropdown.

I have a feeling it's something to do with scaffolding.. but not quite sure.

   public function getCustomSearchContext() {
$fields = $this->scaffoldSearchFields(array(
'restrictFields' => array('Type', 'Regions', 'Budget')
$filters = array(
         'Type' => new ExactMatchFilter('Type'),
         'Budget' => new ExactMatchFilter('Budget'),
         'Regions' => new PartialMatchFilter('Regions')
return new SearchContext(

Regions is defined as a Textfield in the DB, and so it appears as a input textbox on the frontend, but I would like to use a select with specified options, as it is consists of a number of fields which are set with dropdowns.

Is there anything I can do to $fields or something to change the type? I want to change the Textfield into a DropdownField in the front end.

Cheers, would appreciate any help!


24 June 2011 at 12:20am (Last edited: 24 June 2011 12:21am), Community Member, 24 Posts

Solution: define field type in $searchable_fields.

   static $searchable_fields = array(
      'Type' => array(
         'title' => 'I`m looking for...',
         'filter' => 'ExactMatchfilter'),
      'Budget' => array(
         'title' => 'Within a budget of...',
         'filter' => 'ExactMatchfilter'),
      'Regions' => array(
         'title' => 'To perform in...',
         'field' => 'DropdownField',
         'filter' => 'PartialMatchfilter')

And set source/empty fields in getCustomSearchContext() {


I love silverstripe.


20 September 2011 at 5:44pm Community Member, 49 Posts

I'm trying to do something similar here, but am having trouble implementing this solution above. Can anyone help?

My 'Patients' DataObject contains a database field called 'Doctor'. 'Doctor' is an INT field which stores the ID of a member of the 'Doctor' group.

In my Patient ModelAdmin, I want a searchable_field which is a dropdown where I can filter the results by the doctor.

Ideally, the doctor will have the ID as the value of each option, and display the doctor's firstname and surname in the dropdown.

How do I create this searchable_field dropdown box which pulls a groups members and lets you choose a doctor to restrict the results by?


30 December 2012 at 4:25pm Community Member, 58 Posts

@flipsidenz - Were you able to solve the problem?