From 3bed47458ff8fe72cd9e6eecceaf2f8ed9b25f1a Mon Sep 17 00:00:00 2001 From: Yarne Coppens Date: Wed, 4 Sep 2024 11:52:18 +0200 Subject: [PATCH] Fixed autofocus on barcode input --- static/scripts/main.js | 11 +++++++++++ templates/index.jinja | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/static/scripts/main.js b/static/scripts/main.js index 2db1ccd..b093ae2 100644 --- a/static/scripts/main.js +++ b/static/scripts/main.js @@ -41,6 +41,17 @@ async function loadCash(price) { } +async function indexOnLoad(){ + loadProducts(); + document.querySelector("input[autofocus]").addEventListener("blur", function() { + var t = this; + t.focus(); + setTimeout(function() { // Some browsers won't let you do it until + t.focus(); // after the blur has completed + }, 100); + }); +} + async function loadProducts() { const loadProductRequest = new Request(api_url + "/products") all_products = await makeAPIRequest(loadProductRequest) diff --git a/templates/index.jinja b/templates/index.jinja index 1723b69..dadca13 100644 --- a/templates/index.jinja +++ b/templates/index.jinja @@ -11,9 +11,9 @@ - +
- +