learndash.forms=learndash.forms||{},learndash.forms.validation=learndash.forms.validation||{},((e,t,r)=>{r.initRequiredFields=e=>{const i=t=>{if(t.target.matches("input[required]")){if(!r.isFieldFilled(t.target)){let e=t.target.getAttribute("data-learndash-validate-error");e||(e=r.i18n.requiredErrorMessage),r.addError(t.target,e)}r.setSubmitDisableState(e)}};e.addEventListener("blur",i,!0),e.addEventListener("change",i,!0),e.addEventListener("focus",(t=>{t.target.matches("input[required]")&&(r.removeError(t.target),r.setSubmitDisableState(e))}),!0),e.addEventListener("keyup",(t=>{t.target.matches("input[required]")&&r.setSubmitDisableState(e)}),!0),t.addEventListener("learndashPasswordFieldChange",(()=>{r.setSubmitDisableState(e)}),!0)},r.setSubmitDisableState=e=>{const t=e.querySelector('[type="submit"]');t&&(r.isFormFilled(e)&&r.isFormErrorFree(e)?t.removeAttribute("disabled"):t.setAttribute("disabled","disabled"))},r.isFormFilled=e=>{const t=e.querySelectorAll("input[required]");let i=!0;return t.forEach((e=>{r.isFieldFilled(e)||(i=!1)})),i},r.isFormErrorFree=e=>!e.querySelectorAll(".ld-form__field--error, .ld-password-strength.bad").length,r.isFieldFilled=e=>"checkbox"===e?.type?e.checked:""!==e.value.trim(),r.addError=(e,r)=>{e.classList.add("ld-form__field--error"),e.classList.remove("ld-form__field--valid"),e.setAttribute("aria-invalid","true");const i=e.closest(".ld-form__field-wrapper");if(!i)return;if(i.nextElementSibling&&i.nextElementSibling.classList.contains("ld-form__field-error-message"))return;const a=t.createElement("span");a.className="ld-form__field-error-message",a.textContent=r,a.setAttribute("role","alert"),a.setAttribute("aria-live","polite"),a.setAttribute("id",`${e.id}-error`),e.setAttribute("aria-describedby",`${e.id}-error`),i.insertAdjacentElement("afterend",a)},r.removeError=e=>{e.classList.remove("ld-form__field--error"),e.removeAttribute("aria-invalid"),e.removeAttribute("aria-describedby");const t=e.closest(".ld-form__field-wrapper");t&&t.nextElementSibling&&t.nextElementSibling.classList.contains("ld-form__field-error-message")&&t.nextElementSibling.remove()},r.initValidation=()=>{t.querySelectorAll('[data-learndash-validate="true"]').forEach((e=>{r.initRequiredFields(e),r.setSubmitDisableState(e)}))},t.addEventListener("DOMContentLoaded",(()=>{r.initValidation()}))})(window,document,learndash.forms.validation);