Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Limit the results shown in the autocompleter.

  • Loading branch information...
commit 8c0a8539c75e4328504f5fad3d8513a1b7d96772 1 parent 2592f7b
Andrew Short ajshort authored chillu committed
Showing with 24 additions and 2 deletions.
  1. +24 −2 forms/gridfield/GridFieldAddExistingAutocompleter.php
26 forms/gridfield/GridFieldAddExistingAutocompleter.php 100755 → 100644
View
@@ -40,7 +40,12 @@ class GridFieldAddExistingAutocompleter implements GridField_HTMLProvider, GridF
* @var String Text shown on the search field, instructing what to search for.
*/
protected $placeholderText;
-
+
+ /**
+ * @var int
+ */
+ protected $resultsLimit = 20;
+
/**
*
* @param array $searchFields Which fields on the object in the list should be searched
@@ -180,6 +185,7 @@ public function doSearch($gridField, $request) {
}
$results = $allList->where(implode(' OR ', $stmts))->subtract($gridField->getList());
$results = $results->sort($searchFields[0], 'ASC');
+ $results = $results->limit($this->getResultsLimit());
$json = array();
foreach($results as $result) {
@@ -271,7 +277,23 @@ public function getPlaceholderText($dataClass) {
public function setPlaceholderText($text) {
$this->placeholderText = $text;
}
-
+
+ /**
+ * Gets the maximum number of autocomplete results to display.
+ *
+ * @return int
+ */
+ public function getResultsLimit() {
+ return $this->resultsLimit;
+ }
+
+ /**
+ * @param int $limit
+ */
+ public function setResultsLimit($limit) {
+ $this->resultsLimit = $limit;
+ }
+
/**
* This will provide a StartsWith search that only returns a value if we are
* matching ONE object only. We wouldn't want to attach used any object to
Please sign in to comment.
Something went wrong with that request. Please try again.