Update get-gov.js

This commit is contained in:
zandercymatics 2024-01-17 12:10:33 -07:00
parent af656eb5a3
commit 6c6d830e2a
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7

View file

@ -243,9 +243,7 @@ function handleValidationClick(e) {
if (checkAvailabilityButton) { if (checkAvailabilityButton) {
const targetId = checkAvailabilityButton.getAttribute('validate-for'); const targetId = checkAvailabilityButton.getAttribute('validate-for');
const checkAvailabilityInput = document.getElementById(targetId); const checkAvailabilityInput = document.getElementById(targetId);
checkAvailabilityButton.addEventListener('click', function() { checkAvailabilityButton.addEventListener('click', removeFormErrors(checkAvailabilityInput));
removeFormErrors(checkAvailabilityInput);
});
} }
// Add event listener to the alternate domains input // Add event listener to the alternate domains input
@ -254,10 +252,8 @@ function handleValidationClick(e) {
for (const domainInput of alternateDomainsInputs){ for (const domainInput of alternateDomainsInputs){
// Only apply this logic to alternate domains input // Only apply this logic to alternate domains input
if (domainInput.classList.contains('alternate-domain-input')){ if (domainInput.classList.contains('alternate-domain-input')){
domainInput.addEventListener('input', function() { domainInput.addEventListener('input', removeFormErrors(domainInput));
removeFormErrors(domainInput); }
});
}
} }
} }
})(); })();
@ -267,7 +263,7 @@ function handleValidationClick(e) {
*/ */
function removeFormErrors(input){ function removeFormErrors(input){
// Remove error message // Remove error message
const errorMessage = document.getElementById(`${input.id}__error-message`); let errorMessage = document.getElementById(`${input.id}__error-message`);
if (errorMessage) { if (errorMessage) {
errorMessage.remove(); errorMessage.remove();
} }
@ -277,18 +273,16 @@ function removeFormErrors(input){
input.classList.remove('usa-input--error'); input.classList.remove('usa-input--error');
} }
const label = document.querySelector(`label[for="${input.id}"]`); let label = document.querySelector(`label[for="${input.id}"]`);
if (label) { if (label) {
label.classList.remove('usa-label--error'); label.classList.remove('usa-label--error');
// Remove error classes from parent div // Remove error classes from parent div
const parentDiv = label.parentElement; let parentDiv = label.parentElement;
if (parentDiv) { if (parentDiv) {
parentDiv.classList.remove('usa-form-group--error'); parentDiv.classList.remove('usa-form-group--error');
} }
} }
} }
/** /**