Skip to content
This repository
Browse code

Limit the results shown in the autocompleter.

  • Loading branch information...
commit 8c0a8539c75e4328504f5fad3d8513a1b7d96772 1 parent 2592f7b
Andrew Short authored July 17, 2012 chillu committed July 17, 2012
26  forms/gridfield/GridFieldAddExistingAutocompleter.php 100755 → 100644
@@ -40,7 +40,12 @@ class GridFieldAddExistingAutocompleter implements GridField_HTMLProvider, GridF
40 40
 	 * @var String Text shown on the search field, instructing what to search for.
41 41
 	 */
42 42
 	protected $placeholderText;
43  
-	
  43
+
  44
+	/**
  45
+	 * @var int
  46
+	 */
  47
+	protected $resultsLimit = 20;
  48
+
44 49
 	/**
45 50
 	 *
46 51
 	 * @param array $searchFields Which fields on the object in the list should be searched
@@ -180,6 +185,7 @@ public function doSearch($gridField, $request) {
180 185
 		}
181 186
 		$results = $allList->where(implode(' OR ', $stmts))->subtract($gridField->getList());
182 187
 		$results = $results->sort($searchFields[0], 'ASC');
  188
+		$results = $results->limit($this->getResultsLimit());
183 189
 
184 190
 		$json = array();
185 191
 		foreach($results as $result) {
@@ -271,7 +277,23 @@ public function getPlaceholderText($dataClass) {
271 277
 	public function setPlaceholderText($text) {
272 278
 		$this->placeholderText = $text;
273 279
 	}
274  
-	
  280
+
  281
+	/**
  282
+	 * Gets the maximum number of autocomplete results to display.
  283
+	 *
  284
+	 * @return int
  285
+	 */
  286
+	public function getResultsLimit() {
  287
+		return $this->resultsLimit;
  288
+	}
  289
+
  290
+	/**
  291
+	 * @param int $limit
  292
+	 */
  293
+	public function setResultsLimit($limit) {
  294
+		$this->resultsLimit = $limit;
  295
+	}
  296
+
275 297
 	/**
276 298
 	 * This will provide a StartsWith search that only returns a value if we are
277 299
 	 * matching ONE object only. We wouldn't want to attach used any object to

0 notes on commit 8c0a853

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