Skip to content
Snippets Groups Projects
Commit 08cd3a47 authored by Chris Hallberg's avatar Chris Hallberg
Browse files

Make autocomplete auto-submitting configurable.

parent 1060afff
No related merge requests found
......@@ -502,6 +502,8 @@ sort = "last_indexed desc"
enabled = true
; This handler will be used for all search types not covered by [Autocomplete_Types]
default_handler = Solr
; Auto-submit autocomplete on click or enter
auto_submit = true
; In this section, set the key equal to a search handler from searchspecs.yaml and
; the value equal to an autocomplete handler in order to customize autocompletion
......
......@@ -226,6 +226,13 @@ abstract class Options implements TranslatorAwareInterface
*/
protected $autocompleteEnabled = false;
/**
* Autocomplete auto submit setting
*
* @var bool
*/
protected $autocompleteAutoSubmit = false;
/**
* Configuration file to read global settings from
*
......@@ -709,6 +716,16 @@ abstract class Options implements TranslatorAwareInterface
return $this->autocompleteEnabled;
}
/**
* Should autocomplete auto submit?
*
* @return bool
*/
public function autocompleteAutoSubmit()
{
return $this->autocompleteAutoSubmit;
}
/**
* Get a string of the listviewOption (full or tab).
*
......
......@@ -137,10 +137,13 @@ class Options extends \VuFind\Search\Base\Options
$facetConf->Advanced_Facet_Settings->translated_facets->toArray()
);
}
// Load autocomplete preference:
// Load autocomplete preferences:
if (isset($searchSettings->Autocomplete->enabled)) {
$this->autocompleteEnabled = $searchSettings->Autocomplete->enabled;
}
if (isset($searchSettings->Autocomplete->auto_submit)) {
$this->autocompleteAutoSubmit = $searchSettings->Autocomplete->auto_submit;
}
}
/**
......
......@@ -208,10 +208,13 @@ class Options extends \VuFind\Search\Base\Options
$this->highlight = true;
}
// Load autocomplete preference:
// Load autocomplete preferences:
if (isset($searchSettings->Autocomplete->enabled)) {
$this->autocompleteEnabled = $searchSettings->Autocomplete->enabled;
}
if (isset($searchSettings->Autocomplete->auto_submit)) {
$this->autocompleteAutoSubmit = $searchSettings->Autocomplete->auto_submit;
}
// Load shard settings
if (isset($searchSettings->IndexShards)
......
......@@ -126,6 +126,19 @@ class SearchBox extends \Zend\View\Helper\AbstractHelper
return false;
}
/**
* Is autocomplete enabled for the current context?
*
* @param string $activeSearchClass Active search class ID
*
* @return bool
*/
public function autocompleteAutoSubmit($activeSearchClass)
{
$options = $this->optionsManager->get($activeSearchClass);
return $options->autocompleteAutoSubmit();
}
/**
* Are alphabrowse options configured to display in the search options
* drop-down?
......
......@@ -246,17 +246,22 @@ function setupAutocomplete() {
if (searchbox.length < 1) {
return;
}
// Auto-submit based on config
var acCallback = function ac_cb_noop() {};
if (searchbox.hasClass("ac-auto-submit")) {
acCallback = function autoSubmitAC(item, input) {
input.val(item.value);
$("#searchForm").submit();
return false;
};
}
// Search autocomplete
searchbox.autocomplete({
rtl: $(document.body).hasClass("rtl"),
maxResults: 10,
loadingString: VuFind.translate('loading') + '...',
// Auto-submit selected item
callback: function autoSubmitAC(item, input) {
input.val(item.value);
$("#searchForm").submit();
return false;
},
callback: acCallback,
// AJAX call for autocomplete results
handler: function vufindACHandler(input, cb) {
var query = input.val();
......
......@@ -44,7 +44,7 @@
<form id="searchForm" class="searchForm navbar-form navbar-left flip" method="get" action="<?=$this->url($basicSearch)?>" name="searchForm" autocomplete="off">
<?= $this->context($this)->renderInContext('search/searchTabs', ['searchTabs' => $tabConfig['tabs']]); ?>
<?php $placeholder = $this->searchbox()->getPlaceholderText($tabConfig['selected']['id'] ?? null); ?>
<input id="searchForm_lookfor" class="searchForm_lookfor form-control search-query<?php if($this->searchbox()->autocompleteEnabled($this->searchClassId)):?> autocomplete searcher:<?=$this->escapeHtmlAttr($this->searchClassId) ?><?php endif ?>" type="text" name="lookfor" value="<?=$this->escapeHtmlAttr($this->lookfor)?>"<?php if ($placeholder): ?> placeholder="<?=$this->transEsc($placeholder) ?>"<?php endif ?> aria-label="<?=$this->transEsc("search_terms")?>" />
<input id="searchForm_lookfor" class="searchForm_lookfor form-control search-query<?php if($this->searchbox()->autocompleteEnabled($this->searchClassId)):?> autocomplete searcher:<?=$this->escapeHtmlAttr($this->searchClassId) ?><?=$this->searchbox()->autocompleteAutoSubmit($this->searchClassId) ? ' ac-auto-submit' : '' ?><?php endif ?>" type="text" name="lookfor" value="<?=$this->escapeHtmlAttr($this->lookfor)?>"<?php if ($placeholder): ?> placeholder="<?=$this->transEsc($placeholder) ?>"<?php endif ?> aria-label="<?=$this->transEsc("search_terms")?>" />
<?php if ($handlerCount > 1): ?>
<select id="searchForm_type" class="searchForm_type form-control" name="type" data-native-menu="false" aria-label="<?=$this->transEsc("Search type")?>">
<?php foreach ($handlers as $handler): ?>
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment