Skip to content
Snippets Groups Projects
Commit 6396bbb3 authored by David Siegfried's avatar David Siegfried
Browse files

add min-length to quicksearch, closes #2561

Closes #2561

Merge request studip/studip!1728
parent dbc22a10
No related branches found
No related tags found
No related merge requests found
......@@ -43,6 +43,7 @@
<? if ($room_search && !$only_bookable_rooms): ?>
<?= $room_search
->setAttributes(['onFocus' => "jQuery('input[type=radio][name=room][value=room]').prop('checked', 'checked')"])
->setMinLength(2)
->render() ?>
<? else: ?>
<? $selected_room_id = $date->room_booking->resource_id ?? ''; ?>
......
......@@ -34,6 +34,7 @@
<span class="flex-row"></span>
<?= $room_search
->setAttributes(['onFocus' => "jQuery('input[type=radio][name=action][value=room]').prop('checked', true)"])
->setMinLength(2)
->render() ?>
<? if (!$only_bookable_rooms) : ?>
<?= $this->render_partial('course/timesrooms/_bookable_rooms_icon.php') ?>
......
......@@ -94,6 +94,7 @@ class QuickSearch
private $inputClass = null;
private $inputStyle = null;
private $specialQuery = null;
private $minLength = 3;
/**
......@@ -263,6 +264,20 @@ class QuickSearch
return $this;
}
/**
* Set the minimum length to start searching
*
* @param int $minLength
*
* @return QuickSearch
*/
public function setMinLength(int $minLength)
{
$this->minLength = $minLength;
return $this;
}
/**
* disables the select-box, which is displayed for non-JS users who will
* choose with this box, which item they want to have.
......@@ -384,6 +399,7 @@ class QuickSearch
$template->set_attribute('count_QS', self::$count_QS);
$template->set_attribute('id', $this->getId());
$template->set_attribute('query_id', $query_id);
$template->set_attribute('minLength', $this->minLength);
$template->set_attribute('search_button_name', $this->search_button_name);
$template->set_attribute('reset_button_name', $this->reset_button_name);
$template->set_attribute('extendedLayout', $this->hasExtendedLayout());
......
......@@ -13,7 +13,7 @@ const QuickSearch = {
* when user has selected something
* @return: void
*/
autocomplete: function(name, url, func, disabled) {
autocomplete: function(name, url, func, disabled, minLength = 3) {
if (disabled === undefined || disabled !== true) {
var appendTo = 'body';
if (jQuery(`#${name}_frame`).length > 0) {
......@@ -23,7 +23,7 @@ const QuickSearch = {
}
jQuery('#' + name).quicksearch({
delay: 500,
minLength: 3,
minLength: minLength,
appendTo: appendTo,
create: function() {
if ($(this).is('[autofocus]')) {
......
......@@ -29,7 +29,8 @@
STUDIP.QuickSearch.autocomplete("<?= $id ?>",
"<?= URLHelper::getURL("dispatch.php/quicksearch/response/".$query_id) ?>",
<?= $jsfunction ?: 'null' ?>,
<?= $autocomplete_disabled ? "true" : "false" ?>
<?= $autocomplete_disabled ? "true" : "false" ?>,
<?= $minLength ?>
);
});
</script>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment