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   2745 Views

Avatar
bebabeba

Community Member, 192 Posts

22 June 2010 at 7:19pm

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

Community Member, 145 Posts

22 June 2010 at 8:57pm

http://doc.silverstripe.org/checkboxsetfield

Avatar
Willr

Forum Moderator, 5513 Posts

22 June 2010 at 9:16pm

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

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

Avatar
bebabeba

Community Member, 192 Posts

23 June 2010 at 3:57am

Edited: 23/06/2010 4:07am

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

Forum Moderator, 5513 Posts

23 June 2010 at 9:15am

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

Avatar
bebabeba

Community Member, 192 Posts

25 June 2010 at 8:55pm

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

Community Member, 13 Posts

15 December 2012 at 6:20pm

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