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.

Customising the CMS

ListboxField


Reply

3 Posts   710 Views

Avatar
bebabeba

1 September 2011 at 2:24am Community Member, 192 Posts

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

2 September 2011 at 6:36pm Community Member, 192 Posts

any idea???

Avatar
simon_w

2 September 2011 at 7:40pm (Last edited: 2 September 2011 7:41pm), Forum Moderator, 474 Posts

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.