From 6396bbb3c9bbad618c5b4832545ac4f3ccfe3468 Mon Sep 17 00:00:00 2001 From: David Siegfried Date: Wed, 19 Apr 2023 10:57:56 +0000 Subject: add min-length to quicksearch, closes #2561 Closes #2561 Merge request studip/studip!1728 --- app/views/course/timesrooms/editDate.php | 1 + app/views/course/timesrooms/editStack.php | 1 + lib/classes/QuickSearch.class.php | 16 ++++++++++++++++ resources/assets/javascripts/lib/quick_search.js | 4 ++-- templates/quicksearch/inputfield.php | 3 ++- 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 @@ setAttributes(['onFocus' => "jQuery('input[type=radio][name=room][value=room]').prop('checked', 'checked')"]) + ->setMinLength(2) ->render() ?> 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 @@ setAttributes(['onFocus' => "jQuery('input[type=radio][name=action][value=room]').prop('checked', true)"]) + ->setMinLength(2) ->render() ?> 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("", "", , - + , + ); }); -- cgit v1.0