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.

Customising the CMS /

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

ListboxField


Go to End


3 Posts   1725 Views

Avatar
bebabeba

Community Member, 193 Posts

1 September 2011 at 2:24am

Hi!
I define ListboxField as multiple field . My problem is to show value selected. I define an array ($source) to show list of element in ListboxField, and an array ($value) to show selected value after save. What is wrong?

This is my code:
$fields->addFieldToTab("Root.Content.Main", new ListboxField('collezioni','Collezioni',$source, $value, $size=5, $multiple=true,$form=null),'Content');

$value = array(
'a' => 'A',
'd' => 'D',
);

$source = array(
'a' => 'A',
'b' => 'B',
'c' => 'C',
'd' => 'D',
);

Avatar
bebabeba

Community Member, 193 Posts

2 September 2011 at 6:36pm

any idea???

Avatar
(deleted)

Community Member, 473 Posts

2 September 2011 at 7:40pm

Edited: 02/09/2011 7:41pm

There's two things. The first is that the value attribute just wants an array of values, not a value=>name map, so:
$value = array(
'a',
'd',
);
is correct.

The second is that the values for forms in the CMS are loaded from the Page object you're editing. So the value stored in collezioni in the database is what will be displayed as selected. You'll need to define collezioni as a database field type that can store multiple values. Some of them are MultiEnum, Varchar and Text.