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

Can someone provide a working ListboxField example?

Go to End

3 Posts   1014 Views


Community Member, 48 Posts

26 January 2012 at 9:50am

I've spent the better part of the last two days searching the forums and trying to get a working ListboxField (with multiple values). I originally wanted the Listbox populated with values from a Dataobject, but I'll take anything. I have a working CheckboxsetField, but the users think it takes up too much screen space. I thought ListboxField would be the solution, but I can't get it to work. If it does manage to store anything, it stores "Array".



Community Member, 35 Posts

27 January 2012 at 4:52am

Have you looked into the API Documentation on that Class?

There it an example:

new ListboxField(
    $name = "pickanumber",
    $title = "Pick a number",
    $source = array(
       "1" => "one",
       "2" => "two",
       "3" => "three"
    $value = 1

If that doesnt help, post your code =)

Hope that helps


Community Member, 48 Posts

27 January 2012 at 5:21am

Thanks for the help! That example will work with 1 value. Anytime I try to modify it to accept multiple values it stores "Array" instead of the values (even if I pick only 1)

$fields->addFieldToTab('Root.Main', new ListboxField($name = "App2", $title = "App2t", $source = array(
"1" => "one",
"2" => "two",
"3" => "three"
), $value =1,$size = 4,$multiple= true));