diff options
| author | Joe Carstairs <me@joeac.net> | 2026-06-18 19:21:59 +0100 |
|---|---|---|
| committer | Joe Carstairs <me@joeac.net> | 2026-06-18 19:21:59 +0100 |
| commit | ca8e6824eaa711105f4092365792720c9dde026b (patch) | |
| tree | 2b6493941352d11b799ee63d3f1311c13de649b8 /website/src/scripts/otp-form-wc.ts | |
| parent | a0f25057283a397f006127b6f582d190d2c4294e (diff) | |
remove Astro website
Diffstat (limited to 'website/src/scripts/otp-form-wc.ts')
| -rw-r--r-- | website/src/scripts/otp-form-wc.ts | 68 |
1 files changed, 0 insertions, 68 deletions
diff --git a/website/src/scripts/otp-form-wc.ts b/website/src/scripts/otp-form-wc.ts deleted file mode 100644 index 5dd379e..0000000 --- a/website/src/scripts/otp-form-wc.ts +++ /dev/null @@ -1,68 +0,0 @@ -class OtpForm extends HTMLElement { - observer?: MutationObserver; - - 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"); - const inputs = this.querySelectorAll( - 'input:not([type="submit"])', - ) as NodeListOf<HTMLInputElement>; - for (const input of inputs) { - input.value = ""; - } - } - - configureInputs() { - this.observer?.disconnect(); - const inputs = this.querySelectorAll( - 'input:not([type="submit"])', - ) as NodeListOf<HTMLInputElement>; - const form = this.querySelector("form") as HTMLFormElement; - - 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(); - const nextInput = input.nextElementSibling as HTMLInputElement; - if (nextInput) { - nextInput.focus(); - return; - } - - const submitButton = form.querySelector( - 'input[type="submit"]', - ) as HTMLInputElement; - submitButton.focus(); - let areAllInputsEntered = true; - inputs.forEach((input) => { - areAllInputsEntered = areAllInputsEntered && input.value.length > 0; - }); - if (areAllInputsEntered) { - form.requestSubmit(submitButton); - } - } - }); - } - } -} - -customElements.define("otp-form", OtpForm); |
