7912 Posts in 1355 Topics by 930 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » 2 values in dropdown text box
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 350 Views |
-
2 values in dropdown text box

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;
} -
Re: 2 values in dropdown text box

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;
}
} -
Re: 2 values in dropdown text box

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
| 350 Views | ||
|
Page:
1
|
Go to Top |



