Jump to:

5450 Posts in 1672 Topics by 1197 members

Customising the CMS

SilverStripe Forums » Customising the CMS » ListboxField

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

Page: 1
Go to End
Author Topic: 622 Views
  • bebabeba
    Avatar
    Community Member
    192 Posts

    ListboxField Link to this post

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

  • bebabeba
    Avatar
    Community Member
    192 Posts

    Re: ListboxField Link to this post

    any idea???

  • simon_w
    Avatar
    Forum Moderator
    467 Posts

    Re: ListboxField Link to this post

    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.

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