Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make the list used for autocomplete search results settable.

This is useful if you want to limit the autocomplete results to a subset
of all available objects.
  • Loading branch information...
commit 1900842d372fa8d8636da4d4de2c4dcc0f0efefb 1 parent ec25afc
@ajshort ajshort authored wilr committed
Showing with 21 additions and 2 deletions.
  1. +21 −2 forms/gridfield/GridFieldAddExistingAutocompleter.php
View
23 forms/gridfield/GridFieldAddExistingAutocompleter.php
@@ -22,6 +22,11 @@ class GridFieldAddExistingAutocompleter implements GridField_HTMLProvider, GridF
protected $targetFragment;
/**
+ * @var SS_List
+ */
+ protected $searchList;
+
+ /**
* Which columns that should be used for doing a "StartsWith" search.
* If multiple fields are provided, the filtering is performed non-exclusive.
* If no fields are provided, tries to auto-detect a "Title" or "Name" field,
@@ -167,8 +172,12 @@ public function getURLHandlers($gridField) {
* @param SS_HTTPRequest $request
*/
public function doSearch($gridField, $request) {
- $dataClass = $gridField->getList()->dataClass();
- $allList = DataList::create($dataClass);
+ if($this->searchList) {
+ $allList = $this->searchList;
+ } else {
+ $allList = DataList::create($gridField->getList()->dataClass());
+ }
+
$filters = array();
$stmts = array();
@@ -210,6 +219,16 @@ public function getResultsFormat() {
}
/**
+ * Sets the base list instance which will be used for the autocomplete
+ * search.
+ *
+ * @param SS_List $list
+ */
+ public function setSearchList(SS_List $list) {
+ $this->searchList = $list;
+ }
+
+ /**
* @param Array
*/
public function setSearchFields($fields) {
Please sign in to comment.
Something went wrong with that request. Please try again.