Skip to content

Commit

Permalink
Limit the results shown in the autocompleter.
Browse files Browse the repository at this point in the history
  • Loading branch information
ajshort authored and chillu committed Jul 17, 2012
1 parent 2592f7b commit 8c0a853
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions forms/gridfield/GridFieldAddExistingAutocompleter.php 100755 → 100644
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8c0a853

Please sign in to comment.