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   739 Views

Avatar
bebabeba

Community Member, 193 Posts

1 September 2011 at 2:24am

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

Community Member, 193 Posts

2 September 2011 at 6:36pm

any idea???

Avatar
simon_w

Forum Moderator, 474 Posts

2 September 2011 at 7:40pm

Edited: 02/09/2011 7:41pm

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.