Limit the results shown in the autocompleter.

This commit is contained in:
Andrew Short 2012-07-17 19:56:18 +10:00 committed by Ingo Schommer
parent 2592f7bc01
commit 8c0a8539c7

26
forms/gridfield/GridFieldAddExistingAutocompleter.php Executable file → Normal file
View File

@ -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 @@ class GridFieldAddExistingAutocompleter implements GridField_HTMLProvider, GridF
}
$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 @@ class GridFieldAddExistingAutocompleter implements GridField_HTMLProvider, GridF
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