Jump to:

23480 Posts in 18951 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » DropdownField with multiple options

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: 2686 Views
  • bebabeba
    Avatar
    Community Member
    192 Posts

    DropdownField with multiple options Link to this post

    Hi!

    in my admin area I create a new field: DropdownField. This allow me to select one option.
    Is there a field that allow me to select two or more options? I search something similar in Silverstripe documentations but I found nothing..
    can you help me please?

    thanks!!

  • AdamJ
    Avatar
    Community Member
    145 Posts
  • Willr
    Avatar
    Forum Moderator
    5502 Posts
  • bebabeba
    Avatar
    Community Member
    192 Posts

    Re: DropdownField with multiple options Link to this post

    Hi Willr!
    I follow your solution but I have a problem when I save.. 'Error saving content'

    So I write this to allow 3 options:

    static $db = array(
    'MultiypleType' => 'Varchar',
    );

    function getCMSFields() {
    $fields = parent::getCMSFields();

    $array = array(
    '1' => 'aaa',
    '2' => 'bbb',
    '3'=> 'ccc'
    );

    $fields->addFieldToTab("Root.Content.Main", new ListboxField('MultiypleType','MultiypleType',$array,$value = '', $size = 4, $multiple=true),'Content');

    return $fields;
    }

    what is wrong?

  • Willr
    Avatar
    Forum Moderator
    5502 Posts

    Re: DropdownField with multiple options Link to this post

    Check firebug (under console), or your console panel in your browser or your error logs to get the actual error message.

  • bebabeba
    Avatar
    Community Member
    192 Posts

    Re: DropdownField with multiple options Link to this post

    Hi!

    my error is the following:

    500 Warning: "Array to string conversion" at line 109 of D:\_projects\silverstripe\sapphire\core\model\fieldtypes\DBField.php 419ms

    function() {return new ActiveXObject('Microsoft.XMLHTTP')},\n

  • Tony Air
    Avatar
    Community Member
    13 Posts

    Re: DropdownField with multiple options Link to this post

    Hi here's my example of linking items to it self:

    class CatItem extends DataObject {
    ...
    public static $many_many = array(
          'LinkedItems' => 'CatItem',
       );
    ...
    public function getCMSFields() {
          ...
    $fields->removeByName('LinkedItems');
          $fields->insertAfter(
             ListboxField::create(
                'LinkedItems',
                'Linked Items',
                CatItem::get()->map()->toArray()
             )->setMultiple(true),
             'Description'
          );
    ...
    }
    ...
    }


    It saves item list but I get a notice error to fix this you need to open framework/forms/fields/GridField.php, find a line 665 and replace it with
    if($fieldData && isset($fieldData['GridState']) && $fieldData['GridState']) to check if $fieldData['GridState'] is set

    public function handleRequest(SS_HTTPRequest $request, DataModel $model) {
    ...
    if($fieldData && isset($fieldData['GridState']) && $fieldData['GridState'])
    ...
    }

    2686 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.