Jump to:

23380 Posts in 18311 Topics by 2867 members

General Questions

SilverStripe Forums » General Questions » Can someone provide a working ListboxField example?

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

Page: 1
Go to End
Author Topic: 640 Views
  • woodb2
    Avatar
    Community Member
    48 Posts

    Can someone provide a working ListboxField example? Link to this post

    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

  • Ironcheese
    Avatar
    Community Member
    33 Posts

    Re: Can someone provide a working ListboxField example? Link to this post

    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

  • woodb2
    Avatar
    Community Member
    48 Posts

    Re: Can someone provide a working ListboxField example? Link to this post

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

    640 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.