Skip to content
This repository
Browse code

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
Andrew Short authored August 01, 2012 wilr committed August 02, 2012
23  forms/gridfield/GridFieldAddExistingAutocompleter.php
@@ -22,6 +22,11 @@ class GridFieldAddExistingAutocompleter implements GridField_HTMLProvider, GridF
22 22
 	protected $targetFragment;
23 23
 
24 24
 	/**
  25
+	 * @var SS_List
  26
+	 */
  27
+	protected $searchList;
  28
+
  29
+	/**
25 30
 	 * Which columns that should be used for doing a "StartsWith" search.
26 31
 	 * If multiple fields are provided, the filtering is performed non-exclusive.
27 32
 	 * If no fields are provided, tries to auto-detect a "Title" or "Name" field,
@@ -167,8 +172,12 @@ public function getURLHandlers($gridField) {
167 172
 	 * @param SS_HTTPRequest $request 
168 173
 	 */
169 174
 	public function doSearch($gridField, $request) {
170  
-		$dataClass = $gridField->getList()->dataClass();
171  
-		$allList = DataList::create($dataClass);
  175
+		if($this->searchList) {
  176
+			$allList = $this->searchList;
  177
+		} else {
  178
+			$allList = DataList::create($gridField->getList()->dataClass());
  179
+		}
  180
+
172 181
 		$filters = array();
173 182
 		$stmts = array();
174 183
 		
@@ -210,6 +219,16 @@ public function getResultsFormat() {
210 219
 	}
211 220
 
212 221
 	/**
  222
+	 * Sets the base list instance which will be used for the autocomplete
  223
+	 * search.
  224
+	 *
  225
+	 * @param SS_List $list
  226
+	 */
  227
+	public function setSearchList(SS_List $list) {
  228
+		$this->searchList = $list;
  229
+	}
  230
+
  231
+	/**
213 232
 	 * @param Array
214 233
 	 */
215 234
 	public function setSearchFields($fields) {

0 notes on commit 1900842

Please sign in to comment.
Something went wrong with that request. Please try again.