Add searchOnEnter option to make the Search widget fire on enter key (#3524)

Documented in e56468a95b. Credit to @manogi. 
Added an option to change from the "search on every keystroke" functionality to one where the serach is only fired when hitting the enter key. This makes sense when having larger datasets or CMS users who are slow typers.
This commit is contained in:
Sebastian Hilger 2018-04-23 18:09:37 +02:00 committed by Luke Towers
parent 2ffae8ccbc
commit 07dbd0c729
2 changed files with 10 additions and 5 deletions

View File

@ -41,6 +41,11 @@ class Search extends WidgetBase
*/
public $scope;
/**
* @var bool Search on enter key instead of every key stroke.
*/
public $searchOnEnter = false;
//
// Object properties
//
@ -71,6 +76,7 @@ class Search extends WidgetBase
'growable',
'scope',
'mode',
'searchOnEnter',
]);
/*
@ -92,8 +98,7 @@ class Search extends WidgetBase
if ($this->partial) {
return $this->controller->makePartial($this->partial);
}
else {
} else {
return $this->makePartial('search');
}
}
@ -106,6 +111,7 @@ class Search extends WidgetBase
$this->vars['cssClasses'] = implode(' ', $this->cssClasses);
$this->vars['placeholder'] = Lang::get($this->prompt);
$this->vars['value'] = $this->getActiveTerm();
$this->vars['searchOnEnter'] = $this->searchOnEnter;
}
/**
@ -143,8 +149,7 @@ class Search extends WidgetBase
{
if (strlen($term)) {
$this->putSession('term', $term);
}
else {
} else {
$this->resetSession();
}

View File

@ -5,7 +5,7 @@
name="<?= $this->getName() ?>"
value="<?= $value ?>"
data-request="<?= $this->getEventHandler('onSubmit') ?>"
data-track-input
<?= !$searchOnEnter ? 'data-track-input' : '' ?>
data-load-indicator
data-load-indicator-opaque
class="form-control <?= $cssClasses ?>"