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.

General Questions /

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

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

Filtering a DropdownField


Go to End


3 Posts   617 Views

Avatar
woodb2

Community Member, 48 Posts

6 October 2011 at 3:17am

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

Forum Moderator, 1391 Posts

6 October 2011 at 5:13am

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

Avatar
woodb2

Community Member, 48 Posts

6 October 2011 at 6:27am

Thanks!!! That worked perfectly!!!