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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

ListboxField ss3


Go to End


3 Posts   1645 Views

Avatar
merrick_sd

Community Member, 99 Posts

4 January 2013 at 1:36am

Edited: 04/01/2013 1:38am

I want to be able to select multiple items from the siteTree, so i could say asssign a banner to multiple pages.

map() doesn't seem to work anyone know of another way.
[warning] array_keys() expects parameter 1 to be array object given
error line 138 ListboxField.php

line 138 = $hasCommas ....

i did try explode but that doesn't seem to solve

why does map(0 work with checkboxes but not listbox

Checkbox works

 

	      $SiteTreeIDs = SiteTree::get();
	  
	       if (!empty($SiteTreeIDs)) {   
	          $map = $SiteTreeIDs->map('ID', 'Title');
	          $fields->addFieldToTab('Root.Main',
	               new CheckboxSetField(
	                   $name = "selectedPagesFld",
	                    $title = "Select Pages",
	                  $source = $map
	            ));
	            }

ListboxField doesn't

 

 $SiteTreeIDs = SiteTree::get();
	         
 if (!empty($SiteTreeIDs)) {   
	          
	          $treemap = $SiteTreeIDs->map('ID', 'Title');
	          $mylistboxfield = new ListboxField(
                                             'selectedPagesFld',
                                             "Select Pages", 
                                             $source = $treemap,
	                                   $value = ""
	                                   );
	                  
	                 $mylistboxfield->setMultiple(true);    
	               
	                 $fields->addFieldToTab('Root.Main',$mylistboxfield);
	                    
	                    } 
	            
	            
	           /*  */

      return $fields;

Avatar
copernican

Community Member, 189 Posts

8 January 2013 at 5:47am

what about a CheckboxSetField ?

Avatar
Gray

Community Member, 1 Post

24 June 2016 at 2:24pm

I realise this post is a little old, however just stumbled across the same issue today and found the solution. You need to append the method "toArray()" onto the map function:


 $SiteTreeIDs = SiteTree::get();
	         
 if (!empty($SiteTreeIDs)) {   
	          
	          $treemap = $SiteTreeIDs->map('ID', 'Title')->toArray();
	          $mylistboxfield = new ListboxField(
                                             'selectedPagesFld',
                                             "Select Pages", 
                                             $source = $treemap,
	                                   $value = ""
	                                   );
	                  
	                 $mylistboxfield->setMultiple(true);    
	               
	                 $fields->addFieldToTab('Root.Main',$mylistboxfield);
	                    
	                    } 
	            
	            
	           /*  */

      return $fields;