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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

2 values in dropdown text box


Go to End
Reply


3 Posts   799 Views

Avatar
lozhowlett

Community Member, 151 Posts

24 November 2011 at 2:14am

Hi everyone

I want todo something like this...

$CategoriesSource = $oData->toDropDownMap('ID','Name' && 'CarNumber');

I have also tried

$CategoriesSource = $oData->toDropDownMap('ID','Name' . 'CarNumber');

Neither works, however this works...

$CategoriesSource = $oData->toDropDownMap('ID','CarNumber');

The other just preduce blank values in the drop down.

Any ideas?

function getCMSFields_forPopup() {
            $fields = new FieldSet();
            $oData = (DataObject::get('Season','','','','')); 
            if ($oData) {
                $CategoriesSource = $oData->toDropDownMap('ID','Year'); 
            } else {
               // no categories there yet, might put a literalfield to tell the user  
            }
            $dropdown = new DropdownField('SeasonID', 'Season', $CategoriesSource, $this->SeasonID); 
            $fields->push($dropdown);
            
            $oData = (DataObject::get('Team','','','LEFT JOIN `Event_Teams` ON `Event_Teams`.TeamID=`Team`.ID','')); 
            if ($oData) {
                $CategoriesSource = $oData->toDropDownMap('ID','CarNumber'); 
            } else {
               // no categories there yet, might put a literalfield to tell the user  
            }
            $dropdown = new DropdownField('TeamID', 'Team', $CategoriesSource, $this->TeamID); 
            $fields->push($dropdown);

            $fields->push(new NumericField('Position'));
            $fields->push(new NumericField('Points'));
            return $fields;
        }

Avatar
JonoM

Community Member, 113 Posts

24 November 2011 at 11:51am

Hi Lozhowlett,

You can add a function to your Season class that returns the combined values of those two fields, then reference that function in your toDropDownMap call instead of a field.

$CategoriesSource = $oData->toDropDownMap('ID', 'Summary', 'Select...');

class Season extends DataObject {
…

	public function Summary(){
        
		return $this->Name . " " . $this->CarNumber;
		
	}
}

Avatar
Rossel

Community Member, 18 Posts

8 March 2012 at 4:41pm

If someone is looking for a solution to combining values FirstName & Surname together in toDropDownMap:
http://www.silverstripe.org/form-questions/show/10840#post312444