diff options
| author | Joe Carstairs <me@joeac.net> | 2026-08-13 16:33:51 +0100 |
|---|---|---|
| committer | Joe Carstairs <me@joeac.net> | 2026-08-13 16:33:51 +0100 |
| commit | 62e6bab910297aa15d76eb735ce3dd9b5417e26e (patch) | |
| tree | a98b5fb2c2663e08c21475b1092ccec395e2d87e /http/public/scripts/otp-form-wc.js | |
| parent | f9272fdf3ea23070583c944b110a7b8f16c5a4ff (diff) | |
remove website/capsule content
Diffstat (limited to 'http/public/scripts/otp-form-wc.js')
| -rw-r--r-- | http/public/scripts/otp-form-wc.js | 68 |
1 files changed, 0 insertions, 68 deletions
diff --git a/http/public/scripts/otp-form-wc.js b/http/public/scripts/otp-form-wc.js deleted file mode 100644 index 49e1b02..0000000 --- a/http/public/scripts/otp-form-wc.js +++ /dev/null @@ -1,68 +0,0 @@ -class OtpForm extends HTMLElement { - /** @type MutationObserver? */ - observer; - - constructor() { - super(); - } - - connectedCallback() { - this.observer = new MutationObserver(() => { - this.clearInputs(); - this.configureInputs(); - }); - this.observer.observe(this, { childList: true, subtree: true }); - } - - disconnectedCallback() { - this.observer?.disconnect(); - } - - clearInputs() { - console.log("clearing all inputs"); - /** @type NodeListOf<HTMLInputElement> */ - const inputs = this.querySelectorAll('input:not([type="submit"])'); - for (const input of inputs) { - input.value = ""; - } - } - - configureInputs() { - this.observer?.disconnect(); - /** @type NodeListOf<HTMLInputElement> */ - const inputs = this.querySelectorAll('input:not([type="submit"])'); - /** @type NodeListOf<HTMLFormElement> */ - const form = this.querySelector("form"); - - for (const input of inputs) { - input.addEventListener("focus", () => { - input.select(); - }); - - input.addEventListener("input", () => { - if (input.value.length > 0) { - input.value = input.value.slice(0, 1).toLocaleUpperCase(); - /** @type HTMLInputElement */ - const nextInput = input.nextElementSibling; - if (nextInput) { - nextInput.focus(); - return; - } - - /** @type HTMLInputElement */ - const submitButton = form.querySelector('input[type="submit"]'); - submitButton.focus(); - let areAllInputsEntered = true; - inputs.forEach((input) => { - areAllInputsEntered = areAllInputsEntered && input.value.length > 0; - }); - if (areAllInputsEntered) { - form.requestSubmit(submitButton); - } - } - }); - } - } -} - -customElements.define("otp-form", OtpForm); |
