Jump to:

21282 Posts in 5730 Topics by 2601 members

General Questions

SilverStripe Forums » General Questions » SS3 - how to set searchable fields for a dataobject

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

Moderators: martimiz, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w

Page: 1 2
Go to End
Author Topic: 1187 Views
  • BenWu
    Avatar
    Community Member
    65 Posts

    Re: SS3 - how to set searchable fields for a dataobject Link to this post

    many thanks!

    ModelAdmin automatically creates the Contact GridField for the LeadsAdmin. Your codes overwrite that gridfield.

    I think it is a 'bug' that GridFieldAutocompleter doesn't look into the $searchable_fields of the Contact object to find out what searchable_fields are. It only checks if the Contact object has a 'Name' field or not to decide whether the Contact object is searchable or not.

    Although your solution works but i think the perfect solution is to update The GridFieldAutoCompleter. Hope the SS team can look into this?

    regards,
    Ben

  • priithansen
    Avatar
    Community Member
    25 Posts

    Re: SS3 - how to set searchable fields for a dataobject Link to this post

    Yep at the moment it really isn't obvious what went wrong when the "No searchable fields could be found for class ##" error occurs.

  • PmKoetsier
    Avatar
    Community Member
    1 Post

    Re: SS3 - how to set searchable fields for a dataobject Link to this post

    I stumbled over the same bug but after some trial and error I decided to modify the GridFieldAutocompleter in the core. For anyone interested:
    framework/forms/gridfield/GridFieldAddExistingAutocompleter.php line 260

    Old code:

       protected function scaffoldSearchFields($dataClass) {
          $obj = singleton($dataClass);
          if($obj->hasDatabaseField('Title')) {
             return array('Title');
          } else if($obj->hasDatabaseField('Name')) {
             return array('Name');
          } else {
             return null;
          }
       }

    New code:

       protected function scaffoldSearchFields($dataClass) {
          $obj = singleton($dataClass);
          foreach($obj->searchableFields() as $k => $v){
             $searchable[] = $k;
          }
          return $searchable;
       }

    1187 Views
Page: 1 2
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.