From 9afa7d709b010338bea26324977b59142ff1ef62 Mon Sep 17 00:00:00 2001 From: stefan Date: Mon, 18 Nov 2024 23:55:12 +0100 Subject: [PATCH 1/3] automatically select the search input when the start of a scanned uuid is detected --- shimatta_kenkyusho/templates/base.html | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/shimatta_kenkyusho/templates/base.html b/shimatta_kenkyusho/templates/base.html index f7daf6b..82d8bc6 100644 --- a/shimatta_kenkyusho/templates/base.html +++ b/shimatta_kenkyusho/templates/base.html @@ -83,6 +83,14 @@ const popoverTriggerList = document.querySelectorAll('[data-bs-toggle="popover"]') const popoverList = [...popoverTriggerList].map(popoverTriggerEl => new bootstrap.Popover(popoverTriggerEl)) + + {% block custom_scripts %} {% endblock custom_scripts %} From 7c1465428f2414199c990bd7dd15afeac3ad3711 Mon Sep 17 00:00:00 2001 From: stefan Date: Mon, 18 Nov 2024 23:55:38 +0100 Subject: [PATCH 2/3] automatically select first finding in autocomplete fields on enter --- .../static/js/autocomplete-foreign-key-field.js | 15 +++++++++++++-- shimatta_kenkyusho/static/js/autocomplete.js | 4 +++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/shimatta_kenkyusho/static/js/autocomplete-foreign-key-field.js b/shimatta_kenkyusho/static/js/autocomplete-foreign-key-field.js index 0ff2e41..f90e0d5 100644 --- a/shimatta_kenkyusho/static/js/autocomplete-foreign-key-field.js +++ b/shimatta_kenkyusho/static/js/autocomplete-foreign-key-field.js @@ -27,6 +27,17 @@ function initialize_autocompletion_foreign_key_field(search_element) { }); } + // select first match if any on enter + search_element.addEventListener('keydown', (e) => { + if (e.key === "Enter") { + e.preventDefault(); + first_search_result = search_element.parentElement.querySelector('li') + if (first_search_result) { + first_search_result.click() + } + } + }); + new AutocompleteCustomUi( base_id, base_id+'-ac-ul', function(search_query, autocomplete_obj) { api_ajax_request_without_send('GET', search_url+`?search=${encodeURIComponent(search_query)}`, function(method, url, json) { @@ -47,7 +58,7 @@ function initialize_autocompletion_foreign_key_field(search_element) { } } - autocomplete_obj.show_results(nodes, function(data) { + autocomplete_obj.show_results(nodes, function(data) { var name = data['result'][name_field_name]; if (image_field_name != '' && image_field_name != null) { var image = data['result'][image_field_name]; @@ -72,7 +83,7 @@ function initialize_autocompletion_foreign_key_field(search_element) { }); dflex_container.appendChild(span); - }) + }) }, function (){}); } ) diff --git a/shimatta_kenkyusho/static/js/autocomplete.js b/shimatta_kenkyusho/static/js/autocomplete.js index b99c0d0..c99be62 100644 --- a/shimatta_kenkyusho/static/js/autocomplete.js +++ b/shimatta_kenkyusho/static/js/autocomplete.js @@ -38,7 +38,9 @@ class AutocompleteCustomUi { this.query_callback = query_function.bind(this); document.getElementById(text_id).addEventListener("keyup", this.ac_delay(function(event) { - this.query_callback(document.getElementById(this.text_id).value, this); + if (event.key != 'Enter') { + this.query_callback(document.getElementById(this.text_id).value, this); + } }, autocomplete_query_delay_ms).bind(this)); this.dropdown_data = {}; From d10c48f2b9993b9c12594f3165b64fd8cf3c5e57 Mon Sep 17 00:00:00 2001 From: prozessorkern Date: Tue, 19 Nov 2024 00:39:15 +0100 Subject: [PATCH 3/3] fixed usage of input fields --- shimatta_kenkyusho/templates/base.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shimatta_kenkyusho/templates/base.html b/shimatta_kenkyusho/templates/base.html index 82d8bc6..dd94693 100644 --- a/shimatta_kenkyusho/templates/base.html +++ b/shimatta_kenkyusho/templates/base.html @@ -83,10 +83,10 @@ const popoverTriggerList = document.querySelectorAll('[data-bs-toggle="popover"]') const popoverList = [...popoverTriggerList].map(popoverTriggerEl => new bootstrap.Popover(popoverTriggerEl)) - +