diff --git a/src/Forms/GridField/GridFieldAddExistingAutocompleter.php b/src/Forms/GridField/GridFieldAddExistingAutocompleter.php index 6bec9d026..c6b27a47e 100644 --- a/src/Forms/GridField/GridFieldAddExistingAutocompleter.php +++ b/src/Forms/GridField/GridFieldAddExistingAutocompleter.php @@ -12,10 +12,10 @@ use SilverStripe\Forms\TextField; use SilverStripe\ORM\SS_List; use SilverStripe\ORM\DataObject; use SilverStripe\ORM\DataList; +use SilverStripe\ORM\Filters\SearchFilter; use SilverStripe\View\ArrayData; use SilverStripe\View\SSViewer; use LogicException; -use SilverStripe\ORM\Filters\SearchFilter; /** * This class is is responsible for adding objects to another object's has_many @@ -347,7 +347,7 @@ class GridFieldAddExistingAutocompleter extends AbstractGridFieldComponent imple // so we need to check the original setting. // If the field is defined $searchable_fields = array('MyField'), // then default to StartsWith filter, which makes more sense in this context. - if (!$customSearchableFields || array_search($name, $customSearchableFields)) { + if (!$customSearchableFields || array_search($name, $customSearchableFields) !== false) { $filter = 'StartsWith'; } else { $filterName = $spec['filter']; diff --git a/tests/php/Forms/GridField/GridFieldAddExistingAutocompleterTest.php b/tests/php/Forms/GridField/GridFieldAddExistingAutocompleterTest.php index 89b790f7f..7687c5b1a 100644 --- a/tests/php/Forms/GridField/GridFieldAddExistingAutocompleterTest.php +++ b/tests/php/Forms/GridField/GridFieldAddExistingAutocompleterTest.php @@ -14,6 +14,7 @@ use SilverStripe\Forms\Tests\GridField\GridFieldAddExistingAutocompleterTest\Tes use SilverStripe\Forms\Tests\GridField\GridFieldTest\Cheerleader; use SilverStripe\Forms\Tests\GridField\GridFieldTest\Permissions; use SilverStripe\Forms\Tests\GridField\GridFieldTest\Player; +use SilverStripe\Forms\Tests\GridField\GridFieldTest\Stadium; use SilverStripe\Forms\Tests\GridField\GridFieldTest\Team; use SilverStripe\ORM\ArrayList; @@ -29,7 +30,8 @@ class GridFieldAddExistingAutocompleterTest extends FunctionalTest Team::class, Cheerleader::class, Player::class, - Permissions::class + Permissions::class, + Stadium::class, ]; protected static $extra_controllers = [ @@ -41,15 +43,12 @@ class GridFieldAddExistingAutocompleterTest extends FunctionalTest $autoCompleter = new GridFieldAddExistingAutocompleter($targetFragment = 'before', ['Test']); $this->assertEquals( [ - 'Name:PartialMatch', - 'City:StartsWith', - 'Cheerleaders.Name:StartsWith' + 'Name:StartsWith', + 'City:EndsWith', + 'Country:ExactMatch', + 'Type:Fulltext' ], - $autoCompleter->scaffoldSearchFields(Team::class) - ); - $this->assertEquals( - [ 'Name:StartsWith' ], - $autoCompleter->scaffoldSearchFields(Cheerleader::class) + $autoCompleter->scaffoldSearchFields(Stadium::class) ); } diff --git a/tests/php/Forms/GridField/GridFieldTest/Stadium.php b/tests/php/Forms/GridField/GridFieldTest/Stadium.php new file mode 100644 index 000000000..22182b866 --- /dev/null +++ b/tests/php/Forms/GridField/GridFieldTest/Stadium.php @@ -0,0 +1,33 @@ + 'Varchar', + 'City' => 'Varchar', + 'Country' => 'Varchar', + 'Type' => 'Varchar' + ]; + + private static $searchable_fields = [ + 'Name', + 'City' => [ + 'filter' => EndsWithFilter::class + ], + 'Country' => [ + 'filter' => 'ExactMatchFilter' + ], + ]; + + private static $extensions = [ + StadiumExtension::class, + ]; +} diff --git a/tests/php/Forms/GridField/GridFieldTest/StadiumExtension.php b/tests/php/Forms/GridField/GridFieldTest/StadiumExtension.php new file mode 100644 index 000000000..90bba9471 --- /dev/null +++ b/tests/php/Forms/GridField/GridFieldTest/StadiumExtension.php @@ -0,0 +1,16 @@ +