From 5691ea8569ab70a801ff5fc06adfe717a67224a3 Mon Sep 17 00:00:00 2001 From: Miqdad Date: Wed, 20 Aug 2025 11:09:27 +0700 Subject: Block Manual Input from keyboard --- .../static/src/js/check_product_barcode.js | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 indoteknik_custom/static/src/js/check_product_barcode.js (limited to 'indoteknik_custom/static/src') diff --git a/indoteknik_custom/static/src/js/check_product_barcode.js b/indoteknik_custom/static/src/js/check_product_barcode.js new file mode 100644 index 00000000..f7a1bb75 --- /dev/null +++ b/indoteknik_custom/static/src/js/check_product_barcode.js @@ -0,0 +1,41 @@ +odoo.define('indoteknik_custom.prevent_manual_typing', function (require) { + "use strict"; + + console.log("✅ Custom JS from indoteknik_custom loaded!"); + + + const THRESHOLD_MS = 40; // jeda antar karakter dianggap scanner kalau <40ms + let lastTime = 0; + let burstCount = 0; + + function isScannerLike(now) { + const gap = now - lastTime; + lastTime = now; + if (gap < THRESHOLD_MS) { + burstCount += 1; + } else { + burstCount = 1; + } + return burstCount >= 3; // setelah 3 char cepat, dianggap scanner + } + + document.addEventListener('keydown', function (e) { + const t = e.target; + if (!(t instanceof HTMLInputElement)) return; + + // pastikan hanya field code_product + if (t.name !== 'code_product') return; + + const now = performance.now(); + const scanner = isScannerLike(now); + + // enter tetap boleh (scanner biasanya akhiri Enter) + if (e.key === "Enter") return; + + // kalau bukan scanner → blok manual ketikan + if (!scanner) { + e.preventDefault(); + e.stopPropagation(); + } + }, true); +}); -- cgit v1.2.3