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

DropdownField with multiple options


Reply

7 Posts   2723 Views

Avatar
bebabeba

22 June 2010 at 7:19pm Community Member, 192 Posts

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!!

Avatar
AdamJ

22 June 2010 at 8:57pm Community Member, 145 Posts

http://doc.silverstripe.org/checkboxsetfield

Avatar
Willr

22 June 2010 at 9:16pm Forum Moderator, 5511 Posts

ListboxFields also support multiple selections
http://api.silverstripe.org/trunk/forms/fields-basic/ListboxField.html

treemultiselectdropdown
http://doc.silverstripe.org/treemultiselectfield

Avatar
bebabeba

23 June 2010 at 3:57am (Last edited: 23 June 2010 4:07am), Community Member, 192 Posts

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?

Avatar
Willr

23 June 2010 at 9:15am Forum Moderator, 5511 Posts

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

Avatar
bebabeba

25 June 2010 at 8:55pm Community Member, 192 Posts

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

Avatar
Tony Air

15 December 2012 at 6:20pm Community Member, 13 Posts

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'])
...
}