From 1341384a389d8eb9aaa825d36a645afa98dac468 Mon Sep 17 00:00:00 2001 From: Myrne Stol Date: Thu, 16 Dec 2021 15:26:40 +0100 Subject: [PATCH 1/2] Automatically select search query in product list if search query looks like an SKU --- web/js/scripts.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/web/js/scripts.js b/web/js/scripts.js index 76bed2e..86f10db 100644 --- a/web/js/scripts.js +++ b/web/js/scripts.js @@ -1,6 +1,7 @@  $(document).ready(function () { + enableAutoSelect(); $('[data-toggle="tooltip"]').tooltip({ placement: 'auto right', @@ -57,4 +58,21 @@ function focusBarcodeInput() { $('input.focus:first').select(); $('input.focus:first').focus(); //} -} \ No newline at end of file +} + +function enableAutoSelect() { + pathname = window.location.pathname + // only apply this functionality in the product list + if(pathname.indexOf('/product/') === pathname.length-9) { + $("#index_search_form_query").bind("focus", function(event) { + // only select the value if input value looks like a SKU + if(looksLikeSKU(event.currentTarget.value)) { + event.currentTarget.select() + } + }) + } +} + +function looksLikeSKU(string) { + return string.length == 10 && parseInt(string).toString() == string +} From ceb07aaed539a621a6f659c1d76a0d16d63d8864 Mon Sep 17 00:00:00 2001 From: Myrne Stol Date: Fri, 17 Dec 2021 10:31:24 +0100 Subject: [PATCH 2/2] Use regular expression instead of JS code to test for SKU-like string --- web/js/scripts.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/js/scripts.js b/web/js/scripts.js index 86f10db..6b3c449 100644 --- a/web/js/scripts.js +++ b/web/js/scripts.js @@ -74,5 +74,5 @@ function enableAutoSelect() { } function looksLikeSKU(string) { - return string.length == 10 && parseInt(string).toString() == string + return /^\d{10}$/.test(string) }