Jump to:

5513 Posts in 1732 Topics by 1218 members

Customising the CMS

SilverStripe Forums » Customising the CMS » $searchable_fields - Polulating dropdown with CountryDropdownField

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

Page: 1
Go to End
Author Topic: 629 Views
  • Fraser
    Avatar
    Community Member
    46 Posts

    $searchable_fields - Polulating dropdown with CountryDropdownField Link to this post

    Firstly, I am only a couple of days into Silverstripe and OOP, having come from a purely procedural background and thrown in the deep end on a project I've been assigned to so please forgive me if I'm overlooking something very basic and/or fundamental. Also in any responses, please assume you are speaking to a 3yr old. Ha.

    Anyway.

    I have managed to add a drop down labelled "country" to my customer search in the CMS by simply adding :

    Member::$searchable_fields = array(
       'ID' => array(
          'field' => 'NumericField',
          'filter' => 'ExactMatchFilter'
       ),    
       'FirstName',
       'Surname',
       'Email',
       'Client',
       'City',
       
       'Country' => array(
          'field' => 'DropdownField'
       )
    );

    I need this to take the form of CountryDropdownField.

    Is this possible and how do I go about this?

    Many thanks in advance.

  • Fraser
    Avatar
    Community Member
    46 Posts

    Re: $searchable_fields - Polulating dropdown with CountryDropdownField Link to this post

    Solved. It was much simpler than I thought.

    It needed to read like this:

    .....
    'Country' => array(
       'field' => 'CountryDropdownField'
    )
    ....

  • Fraser
    Avatar
    Community Member
    46 Posts

    Re: $searchable_fields - Polulating dropdown with CountryDropdownField Link to this post

    OK, so I have another question about this. How do I have a blank entry to allow "all countries" to be searched?

  • Spambanjo
    Avatar
    Community Member
    15 Posts

    Re: $searchable_fields - Polulating dropdown with CountryDropdownField Link to this post

    I know this isn't the solution for your exact problem, but yours is the only thread I could find while looking for a fix to a similar problem and thought it may be handy to post my solution here for anyone who may be looking for the same issue as me.

    This is how you would add a blank first entry into a CountryDropdownField in the CMS or model admin of a Silverstripe 2.4 site.

    $f = parent::getCMSFields();
    $cf = new CountryDropdownField("Country", "Country") ;
    $cf->setHasEmptyDefault(1);
    $f->addFieldToTab("Root.Content.Main", $cf);
    return $f ;

    Apologies for the slight thread hijack but I'm certain someone will appreciate this post.

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