From a9a454d36e985d68c3d9a3fb7b19c01c00aa4a14 Mon Sep 17 00:00:00 2001 From: Will Rossiter Date: Tue, 17 Mar 2020 06:28:43 +1300 Subject: [PATCH] Add filter example (Fixes #40) --- README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/README.md b/README.md index 146ab9a..cca06ee 100644 --- a/README.md +++ b/README.md @@ -38,3 +38,24 @@ composer require silvershop/silverstripe-hasonefield You must pass through the parent context ($this), so that the `has_one` relationship can be set by the `GridFieldDetailForm`. + +## Filtering Results + +To filter the results shown in the picker use `HasOneAddExistingAutoCompleter::setSearchList`. + +```php +$property = HasOneButtonField::create( + $this, + 'Address' +); + +$property + ->getConfig() + ->getComponentByType(HasOneAddExistingAutoCompleter::class) + ->setSearchList(Property::get()->filter("Country", "GB")); + +$fields->addFieldToTab( + 'Root.Main', + $property +); +```