Jump to:

7939 Posts in 1472 Topics by 944 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, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 516 Views
  • lozhowlett
    Avatar
    Community Member
    140 Posts

    2 values in dropdown text box Link to this post

    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;
    }

  • JonoM
    Avatar
    Community Member
    103 Posts

    Re: 2 values in dropdown text box Link to this post

    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;
          
       }
    }

  • Rossel
    Avatar
    Community Member
    18 Posts

    Re: 2 values in dropdown text box Link to this post

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

    516 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.