mirror of
https://github.com/wintercms/winter.git
synced 2024-06-28 05:33:29 +02:00
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:
parent
2ffae8ccbc
commit
07dbd0c729
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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 ?>"
|
||||
|
Loading…
x
Reference in New Issue
Block a user