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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

Multiselect ListBoxField in Admin SS2.4


Go to End


2 Posts   1138 Views

Avatar
Lazarus404

Community Member, 72 Posts

26 February 2014 at 6:03am

Hi guys,

So, I have a dataobject type, which is managed from the CMS. One of the page types in my site can have one or more of these dataobjects assigned.

//page class 
public static $belongs_many_many = array( 
   'DataObjectList' => 'MyDataObject', 
);

//data object 
public static $many_many = array( 
'Pages' => 'MyPage' 
);

The page type has a listboxfield with multiselect set to true and populated with all of the available dataobjects, like so:

$dropdown = new ListboxField('DataObjectList', _t('DATAOBJECTS', 'Data Objects'), DataObject::get('MyDataObject', "", 'Name DESC')->toDropDownMap()); 
$dropdown->setMultiple(true); 
$fields->addFieldToTab('Root.Content.Main', $dropdown, 'Content');

Now, this displays fine in the CMS admin, but when one or more items are selected in the admin, they don't save. What do I need to do to make this happen?

Thanks loads,
Lee

Avatar
Lazarus404

Community Member, 72 Posts

27 February 2014 at 5:31am

Anybody? It's driving me nuts.

Thanks,
Lee