Jump to:

22972 Posts in 11596 Topics by 2824 members

General Questions

SilverStripe Forums » General Questions » Pass CheckboxSetField array to DropdownField?

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

Page: 1
Go to End
Author Topic: 1368 Views
  • AlaVive
    Avatar
    Community Member
    42 Posts

    Pass CheckboxSetField array to DropdownField? Link to this post

    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?

    <?php

    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(
                'Name',
                'Brand',
                'Language',
                'Type'
                )
          ));
          
          /*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(
             $this->class,
             $fields,
             $filters
          );
       }

    }
    ?>

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

    Thanks in advance.

  • AlaVive
    Avatar
    Community Member
    42 Posts

    Re: Pass CheckboxSetField array to DropdownField? Link to this post

    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.

    Anyone?

    1368 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.