aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Siegfried <david.siegfried@uni-vechta.de>2023-04-19 10:57:56 +0000
committerDavid Siegfried <david.siegfried@uni-vechta.de>2023-04-19 10:57:56 +0000
commit6396bbb3c9bbad618c5b4832545ac4f3ccfe3468 (patch)
treefd651e0e0c6ad31ad91d9990666555df47f46db4
parentdbc22a10dd185b4d3cc70ff827f8693e30636f0d (diff)
add min-length to quicksearch, closes #2561
Closes #2561 Merge request studip/studip!1728
-rw-r--r--app/views/course/timesrooms/editDate.php1
-rw-r--r--app/views/course/timesrooms/editStack.php1
-rw-r--r--lib/classes/QuickSearch.class.php16
-rw-r--r--resources/assets/javascripts/lib/quick_search.js4
-rw-r--r--templates/quicksearch/inputfield.php3
5 files changed, 22 insertions, 3 deletions
diff --git a/app/views/course/timesrooms/editDate.php b/app/views/course/timesrooms/editDate.php
index fa9635f..3be5e7c 100644
--- a/app/views/course/timesrooms/editDate.php
+++ b/app/views/course/timesrooms/editDate.php
@@ -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 ?? ''; ?>
diff --git a/app/views/course/timesrooms/editStack.php b/app/views/course/timesrooms/editStack.php
index d14db19..c664f5e 100644
--- a/app/views/course/timesrooms/editStack.php
+++ b/app/views/course/timesrooms/editStack.php
@@ -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') ?>
diff --git a/lib/classes/QuickSearch.class.php b/lib/classes/QuickSearch.class.php
index 69a80f7..d3983a3 100644
--- a/lib/classes/QuickSearch.class.php
+++ b/lib/classes/QuickSearch.class.php
@@ -94,6 +94,7 @@ class QuickSearch
private $inputClass = null;
private $inputStyle = null;
private $specialQuery = null;
+ private $minLength = 3;
/**
@@ -264,6 +265,20 @@ class QuickSearch
}
/**
+ * 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());
diff --git a/resources/assets/javascripts/lib/quick_search.js b/resources/assets/javascripts/lib/quick_search.js
index a755184..115941b 100644
--- a/resources/assets/javascripts/lib/quick_search.js
+++ b/resources/assets/javascripts/lib/quick_search.js
@@ -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]')) {
diff --git a/templates/quicksearch/inputfield.php b/templates/quicksearch/inputfield.php
index 4dd569f..6f2cb3f 100644
--- a/templates/quicksearch/inputfield.php
+++ b/templates/quicksearch/inputfield.php
@@ -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>