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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Call nested DOM in DropdownField


Go to End


2 Posts   797 Views

Avatar
Bereusei

Community Member, 96 Posts

12 January 2012 at 11:19pm

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.

Avatar
Bereusei

Community Member, 96 Posts

13 January 2012 at 1:25am

Edited: 13/01/2012 1:26am

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.