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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Pass CheckboxSetField array to DropdownField?


2 Posts   1470 Views


Community Member, 42 Posts

10 November 2009 at 5:00pm

Edited: 12/11/2009 10:41am

I always feel like I'm posting to the wrong place on the forums, but I'm taking a stab at this again.

I'm using a CheckboxSetField to add multiple brand names to each PDF that's uploaded to a technical documents section of the site.

I need to be able to search the different PDF files using "Brands" as a field, but I wan to be able to pass the array of options to a dropdown, rather than a text search.

Using ComplexSearch, is there a way to pass the array from the CheckboxSetField to a dropdown?


class TechDoc extends DataObject
   static $db = array (
      'Name' => 'Text',
      'Brand' => 'Varchar',
      'Description' => 'Text',
      'Language' => "Enum('English, French, Spanish, Portuguese, Polish, German')"
   static $has_one = array (
      'Attachment' => 'File',
      'TechDocPage' => 'TechDocPage'
   static $has_many = array(
      'TechDoc' => 'Brand'


   public function getCMSFields_forPopup()
      return new FieldSet(
         new TextField('Name'),
         new TextareaField('Description'),
         new CheckboxSetField('Brand','Brand',(array ("BrandA" => "BrandA","BrandB" => "BrandB","BrandC" => "BrandC"))),
         new DropdownField('Language','Language', singleton('TechDoc')->dbObject('Language')->enumValues()),
         new FileIFrameField('Attachment')
   static $searchable_fields = array(
         'Name' => 'PartialMatchFilter',
         'Language' => 'ExactMatchFilter',
         'Description' => 'PartialMatchFilter',
   /*This does work, but I need a dropdown*/
      'Brand' => 'PartialMatchFilter'
         /*This does not work, since I can't pass it the array for the dropdown:
      'Brand' => array(
          'title' => 'Brand',
          'field' => 'DropdownField',
          'filter' => 'PartialMatchFilter'
   public function getCustomSearchContext() {
      $fields = $this->scaffoldSearchFields(array(
         'restrictFields' => array(
      /*This seems redundant, but I'm working from the tutorial...*/
      $filters = array(
         'Name' => new PartialMatchFilter('Name'),
         'Brand' => new PartialMatchFilter('Brand'),
         'Language' => new ExactMatchFilter('Language'),
         'Type' => new PartialMatchFilter('Type')
      return new SearchContext(


If there's a better way to do this, I'm perfectly happy to know how I might change this ;-).

Thanks in advance.


Community Member, 42 Posts

12 November 2009 at 10:40am

Edited: 12/11/2009 10:41am

I'm sure there's probably a better way to ask this-- that's part of my problem.

But, even if I find out what I need to do is impossible, it would save me some time and a boat-load of stress.