diff --git a/app/views/course/timesrooms/editDate.php b/app/views/course/timesrooms/editDate.php index fa9635f585e472b5361a58426e451edbc9547dc6..3be5e7c709fea0b756848d076f03d518ae752610 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 d14db1970de021b324fa5cb109fb7169e5d50e57..c664f5e1f2061e440af3cd682448d0e1104cffb7 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 69a80f7c247a3d2d70da84fe97e450ae4ed5ec3b..d3983a33bc73369cc4481e2ab4d980d040a0c2e1 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; /** @@ -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()); diff --git a/resources/assets/javascripts/lib/quick_search.js b/resources/assets/javascripts/lib/quick_search.js index a755184a5710ef5d8e1d84064d0e5d1ce773da96..115941b2918ab945e11aed19bf2612d5586d776d 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 4dd569f9e353aab49f85c614665389f0cead8a98..6f2cb3fb01cb8224323de8531effb4de6bfa86a4 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>