Jump to:

7937 Posts in 1537 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Call nested DOM in DropdownField

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: 363 Views
  • Bereusei
    Avatar
    Community Member
    94 Posts

    Call nested DOM in DropdownField Link to this post

    Hey guys,

    I´ve created an DOM (Workshoptraining) in an DOM (Workshop) (thanks to UncleCheese). Imagine a Workshop, that occure on a particular day.
    That workshop has many trainingsessions (on 11.00, on 12.00, ...)

    Now I´ve created an form with two DropDownFields, where users can registrate.
    With the DropDownFields they can select a Workshop (on monday for example) and then they must select a trainingsession (11:00) for this particular workshop.
    I figured out, how I can call each DataObject to list the elements in the DropDownFields, but instead of getting only the sessions for the particular workshop, I get all sessions from all workshops. How can I filter my list in the second DropDownField, so that I get only the sessions from the workshop, that I´ve selected before?

    //my Workshop class extends DataObject
    ...
    public function getCMSFields()
    {
    return new FieldSet(
    new DateField('Date'),
    new TextField('Workshopname'),
    new TextField('Coach'),
    new DataObjectManager(
          $this,
          'Workshoptrainingsessions',
          'Workshoptraining',
          array('Time' => 'Time', 'Type' => 'Type')
       )
    )
    }

    //my Workshoptraining class extends DataObject
    ...

    //Fields for the DOM Popup
    public function getCMSFields()
    {
    return new FieldSet(
       new TimeField('Zeit'),
       new TextField('Type')
    );

    }

    //in my Page_Controller
    function getWorkshops()
          {
             if($Workshops = DataObject::get('Workshop'))
          {
             return $Workshops->map('Workshopname', 'Workshopname', 'Please Select');
          }
          else
          {
             return array('No Objects found');
          }
          }
          
          function getWorkshopTimes()
          {
             if($Workshops = DataObject::get('Workshoptraining'))
          {
             return $Workshops->map('Time', 'Time', 'Please Select');
          }
          else
          {
             return array('No Objects found');
          }
          }
          
          function Form(){
             $fields = new FieldSet(
                new DropdownField(
                'Workshops',
                'Please choose an object',
                $this->getWorkshops()
                ),
                new DropdownField(
                'Time',
                'Please choose an object',
                $this->getWorkshopTimes()
                )
             );

    I hope, that I´ve described what I want and the problem clear enough and hope someone can help.

  • Bereusei
    Avatar
    Community Member
    94 Posts

    Re: Call nested DOM in DropdownField Link to this post

    In my opinion I must use the FilteredDropdownSet. I´ve figured this out:

    $map_of_Workshop = array();
             $map_of_Workshoptraining = array();
             
             if($result = DataObject::get("Workshop")) {
                $map_of_Workshop = $result->toDropdownMap('Workshopname', 'Workshopname', 'Please Select');
       }

       if($result = DataObject::get("Workshoptraining")) {
       $map_of_Workshoptraining = $result->toDropdownMap('Time', 'Time', 'Please Select');

       }

          
             $fields = new FieldSet(
                new FilteredDropdownSet(
                   array(
                      $Workshop = new DropdownField('WorkshopID','Workshops',$map_of_Workshop),
                      $Workshoptraining = new DropdownField('Time','Time',$map_of_Workshoptraining)
                   ),
                   "WorkshopID",
                   "Time"
                )
             );

    But I get the same result. I get all sessions from all workshops, instead of only the sessions from the selected workshop.

    363 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.