diff options
| author | Miqdad <ahmadmiqdad27@gmail.com> | 2025-08-20 11:09:27 +0700 |
|---|---|---|
| committer | Miqdad <ahmadmiqdad27@gmail.com> | 2025-08-20 11:09:27 +0700 |
| commit | 5691ea8569ab70a801ff5fc06adfe717a67224a3 (patch) | |
| tree | 06745477ad13ccae44112385f393e1780c1c9229 /indoteknik_custom/static/src | |
| parent | c225119cb9bdcee03ca9706ec58dfceb717b5027 (diff) | |
<Miqdad> Block Manual Input from keyboard
Diffstat (limited to 'indoteknik_custom/static/src')
| -rw-r--r-- | indoteknik_custom/static/src/js/check_product_barcode.js | 41 |
1 files changed, 41 insertions, 0 deletions
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); +}); |
