Skip to content

Commit

Permalink
Make the list used for autocomplete search results settable.
Browse files Browse the repository at this point in the history
This is useful if you want to limit the autocomplete results to a subset
of all available objects.
  • Loading branch information
ajshort authored and wilr committed Aug 2, 2012
1 parent ec25afc commit 1900842
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions forms/gridfield/GridFieldAddExistingAutocompleter.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ class GridFieldAddExistingAutocompleter implements GridField_HTMLProvider, GridF
*/ */
protected $targetFragment; protected $targetFragment;


/**
* @var SS_List
*/
protected $searchList;

/** /**
* Which columns that should be used for doing a "StartsWith" search. * Which columns that should be used for doing a "StartsWith" search.
* If multiple fields are provided, the filtering is performed non-exclusive. * If multiple fields are provided, the filtering is performed non-exclusive.
Expand Down Expand Up @@ -167,8 +172,12 @@ public function getURLHandlers($gridField) {
* @param SS_HTTPRequest $request * @param SS_HTTPRequest $request
*/ */
public function doSearch($gridField, $request) { public function doSearch($gridField, $request) {
$dataClass = $gridField->getList()->dataClass(); if($this->searchList) {
$allList = DataList::create($dataClass); $allList = $this->searchList;
} else {
$allList = DataList::create($gridField->getList()->dataClass());
}

$filters = array(); $filters = array();
$stmts = array(); $stmts = array();


Expand Down Expand Up @@ -209,6 +218,16 @@ public function getResultsFormat() {
return $this->resultsFormat; return $this->resultsFormat;
} }


/**
* 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 * @param Array
*/ */
Expand Down

0 comments on commit 1900842

Please sign in to comment.