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.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Filtering a DropdownField


Reply

3 Posts   347 Views

Avatar
woodb2

6 October 2011 at 3:17am Community Member, 48 Posts

I have a FamilyPage and a dataobject "Jobs"

In FamilyPage I can create the DropDown:

function getCMSFields()

   {

      $fields = parent::getCMSFields();

$jobsob = DataObject::get('Jobs');
$fields->addFieldToTab('Root.Content.Band5', new DropdownField('JobTitle', 'Jobs', $Jobsob->map()));

The dropdown works, except it show every job in the dataobject (which it should).

I can manually get the correct ones using:

$jobsob = DataObject::get('Jobs', 'FamiliesID = 226'); // I know 226 is the ID of one of the FamilyPages
$fields->addFieldToTab('Root.Content.Band5', new DropdownField('JobTitle', 'Jobs', $Jobsob->map()));

How do I replace "FamiliesID = 226" with the ID of the FamilyPage that I am currently in?

Thanks,
Brian

Avatar
martimiz

6 October 2011 at 5:13am Forum Moderator, 1091 Posts

$jobsob = DataObject::get('Jobs', "FamiliesID = {$this->ID}");

Avatar
woodb2

6 October 2011 at 6:27am Community Member, 48 Posts

Thanks!!! That worked perfectly!!!