seepur/resources/scripts/views/register.ts
2020-02-15 13:07:23 -05:00

25 lines
968 B
TypeScript

document.addEventListener("DOMContentLoaded", () => {
let isFormValid = false;
let isPassMatch = false;
const form = document.getElementById('form-register') as HTMLFormElement;
const pass = document.getElementById('txt-register-password') as HTMLInputElement;
const confirmPass = document.getElementById('txt-register-confirm-password') as HTMLInputElement;
const terms = document.getElementById('chk-register-terms') as HTMLInputElement;
const submit = document.getElementById('btn-register-submit') as HTMLButtonElement;
if (!pass || !confirmPass || !terms) alert('Something Went wrong');
form.oninput = (ev: Event) => {
isPassMatch = (pass.value === confirmPass.value) && !!pass.value.trim().length;
validateForm();
}
function validateForm(): void {
isFormValid = form.checkValidity() && isPassMatch && terms.checked;
submit.disabled = !isFormValid;
terms.value = terms.checked ? "on" : "";
}
validateForm();
});