{"version":3,"file":"contact_delegate_form.js","mappings":"AACiBA,SAASC,cAAc,QA+D7BC,iBAAiB,UArCNC,IACpB,MAAMC,EAAcJ,SAASK,eAAe,cAG5C,IAzB6B,MAC7B,IAAIC,GAAU,EAiBd,OAhBuBN,SAASO,iBAAiB,mBAClCC,SAASC,IACtB,MAAMC,EAAeD,EAAQE,cAAcV,cAAc,qBACnC,KAAlBQ,EAAQG,OACVN,GAAU,EACVG,EAAQI,UAAUC,IAAI,kBACtBL,EAAQI,UAAUC,IAAI,aACtBL,EAAQI,UAAUE,OAAO,sBACzBL,EAAaG,UAAUE,OAAO,eAE9BN,EAAQI,UAAUE,OAAO,kBACzBN,EAAQI,UAAUE,OAAO,aACzBN,EAAQI,UAAUC,IAAI,sBACtBJ,EAAaG,UAAUC,IAAI,aAC7B,IAEKR,CAAO,EAKEU,GAKd,OAFAZ,EAAYa,UAAY,kDACxBd,EAAEe,iBAKJ,MAAMC,EAAanB,SAASK,eAAe,iBACrCe,EAAyBpB,SAASK,eAAe,8BACvD,GAAIc,EAAWP,QAAUQ,EAAuBR,MAK9C,OAJAO,EAAWN,UAAUC,IAAI,kBACzBM,EAAuBP,UAAUC,IAAI,kBACrCV,EAAYa,UAAY,4BACxBd,EAAEe,iBAGFC,EAAWN,UAAUE,OAAO,kBAC5BK,EAAuBP,UAAUE,OAAO,kBAI1C,MAAMM,EAAerB,SAASK,eAAe,mBAC7C,GAAIgB,EAAaT,MAAMU,OAAS,IAI9B,OAHAD,EAAaE,MAAMV,UAAUC,IAAI,kBACjCV,EAAYa,UAAY,sDACxBd,EAAEe,iBAGFG,EAAaE,MAAMV,UAAUE,OAAO,iBACtC","sources":["webpack://app/./app/javascript/packs/contact_delegate_form.js"],"sourcesContent":["\nconst mainForm = document.querySelector(\"form\");\n\n// This checks if the elements with the class \"required-field\" are empty\n// and returns false is any element is empty; otherwise, it returns true.\n// It also sets the border color of the empty required elements to red.\nconst validateRequiredFields = () => {\n let isValid = true; // Default to true\n const requiredFields = document.querySelectorAll(\".required-field\");\n requiredFields.forEach((element) => {\n const errorMessage = element.parentElement.querySelector(\".invalid-feedback\");\n if (element.value === \"\") {\n isValid = false;\n element.classList.add('border-red-250');\n element.classList.add('bg-red-50');\n element.classList.remove('border-primary-100');\n errorMessage.classList.remove('invisible');\n } else {\n element.classList.remove('border-red-250');\n element.classList.remove('bg-red-50');\n element.classList.add('border-primary-100');\n errorMessage.classList.add('invisible');\n }\n });\n return isValid;\n}\n\nconst handleSubmit = (e) => {\n const fieldsError = document.getElementById(\"validError\");\n const isValid = validateRequiredFields();\n\n if (!isValid) {\n fieldsError.innerHTML = 'Please fill out all required fields above.';\n e.preventDefault();\n return;\n }\n\n // Validate that the email and email confirmation fields match\n const emailField = document.getElementById(\"indigov_email\");\n const emailConfirmationField = document.getElementById(\"indigov_email_confirmation\");\n if (emailField.value !== emailConfirmationField.value) {\n emailField.classList.add('border-red-250');\n emailConfirmationField.classList.add('border-red-250');\n fieldsError.innerHTML = 'Emails do not match.';\n e.preventDefault();\n return;\n } else {\n emailField.classList.remove('border-red-250');\n emailConfirmationField.classList.remove('border-red-250');\n }\n\n // Validate that the subject field is not greater than 100 characters\n const subjectField = document.getElementById(\"indigov_subject\");\n if (subjectField.value.length > 100) {\n subjectField.style.classList.add('border-red-250');\n fieldsError.innerHTML = 'Subject cannot be greater than 100 characters.';\n e.preventDefault();\n return;\n } else {\n subjectField.style.classList.remove('border-red-250');\n }\n}\n\nconst setUpListeners = () => {\n mainForm.addEventListener(\"submit\", handleSubmit);\n}\n\nconst init = () => {\n setUpListeners();\n}\n\ninit();"],"names":["document","querySelector","addEventListener","e","fieldsError","getElementById","isValid","querySelectorAll","forEach","element","errorMessage","parentElement","value","classList","add","remove","validateRequiredFields","innerHTML","preventDefault","emailField","emailConfirmationField","subjectField","length","style"],"sourceRoot":""}