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

Can someone provide a working ListboxField example?


Reply


3 Posts   798 Views

Avatar
woodb2

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".

Thanks,
Brian

Avatar
Ironcheese

Community Member, 33 Posts

27 January 2012 at 4:52am

Have you looked into the API Documentation on that Class?

http://api.silverstripe.org/2.4/forms/fields-basic/ListboxField.html

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

Avatar
woodb2

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));