Jump to:

23368 Posts in 18143 Topics by 2863 members

General Questions

SilverStripe Forums » General Questions » Filtering a DropdownField

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

Page: 1
Go to End
Author Topic: 326 Views
  • woodb2
    Avatar
    Community Member
    48 Posts

    Filtering a DropdownField Link to this post

    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

  • martimiz
    Avatar
    Forum Moderator
    1067 Posts

    Re: Filtering a DropdownField Link to this post

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

  • woodb2
    Avatar
    Community Member
    48 Posts

    Re: Filtering a DropdownField Link to this post

    Thanks!!! That worked perfectly!!!

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