Multi-select search

Silverstripe Version:
4
Question:
I’m trying to add a multi-select field in an admin screen
Details of your query go here
Does anyone have a working example of a multi select working in the $searchable_fields scope?

// Include any relevant code. If you have a lot of code, link to a gist instead.

Do you want to add this to a specific admin, or to any admin that the dataobject you’re interested in happens to be displayed in?

If it’s for a specific admin, if that admin is a subclass of ModelAdmin the easiest way is probably to create an extension which implements updateSearchForm().

If you want to apply this to the search form of an admin the dataobject is displayed in, you can implement scaffoldSearchFields() directly in the class (don’t forget to call $fields = parent::scaffoldSearchFields(); in that method). Something like this:

public function scaffoldSearchFields($_params = null)
    {
        $fields = parent::scaffoldSearchFields($_params);
        $fields->replace('Name', DropdownField::create('Name')->setSource(static::get()->map('Name', 'Name')));
        return $fields;
    }

If it’s a dataobject you don’t have control over (e.g. from some module)… well, comment back if that’s the case and I’ll see what options you have, but it’ll get pretty hairy for that situation. There’s no extension point in scaffoldSearchFields() at the moment.