mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-04 00:42:16 +02:00
Rename functions for clarity
This commit is contained in:
parent
5e27ec571d
commit
d2f6988bd8
2 changed files with 12 additions and 12 deletions
|
@ -203,7 +203,7 @@ function handleInputValidation(e) {
|
|||
}
|
||||
|
||||
/** On button click, handles running any associated validators. */
|
||||
function handleValidationClick(e) {
|
||||
function validateFieldInput(e) {
|
||||
const attribute = e.target.getAttribute("validate-for") || "";
|
||||
if (!attribute.length) return;
|
||||
const input = document.getElementById(attribute);
|
||||
|
@ -212,7 +212,7 @@ function handleValidationClick(e) {
|
|||
}
|
||||
|
||||
|
||||
function handleFormsetValidationClick(e, availabilityButton) {
|
||||
function validateFormsetInputs(e, availabilityButton) {
|
||||
|
||||
// Collect input IDs from the repeatable forms
|
||||
let inputs = Array.from(document.querySelectorAll('.repeatable-form input'))
|
||||
|
@ -247,26 +247,26 @@ function handleFormsetValidationClick(e, availabilityButton) {
|
|||
for(const input of needsValidation) {
|
||||
input.addEventListener('input', handleInputValidation);
|
||||
}
|
||||
const alternativeDomainsAvailability = document.getElementById('check-avail-for-alt-domains');
|
||||
const alternativeDomainsAvailability = document.getElementById('validate-alt-domains-availability');
|
||||
const activatesValidation = document.querySelectorAll('[validate-for]');
|
||||
|
||||
for(const button of activatesValidation) {
|
||||
// Adds multi-field validation for alternative domains
|
||||
if (button === alternativeDomainsAvailability) {
|
||||
button.addEventListener('click', (e) => {
|
||||
handleFormsetValidationClick(e, alternativeDomainsAvailability)
|
||||
validateFormsetInputs(e, alternativeDomainsAvailability)
|
||||
});
|
||||
} else {
|
||||
button.addEventListener('click', handleValidationClick);
|
||||
button.addEventListener('click', validateField);
|
||||
}
|
||||
}
|
||||
|
||||
// Add event listener to the alternate domains input
|
||||
const alternateDomainsInputs = document.querySelectorAll('[auto-validate]');
|
||||
if (alternateDomainsInputs) {
|
||||
for (const domainInput of alternateDomainsInputs){
|
||||
domainInput.addEventListener('input', function() {
|
||||
removeFormErrors(domainInput, true);
|
||||
// Clear errors on auto-validated inputs when user reselects input
|
||||
const autoValidateInputs = document.querySelectorAll('[auto-validate]');
|
||||
if (autoValidateInputs) {
|
||||
for (const input of autoValidateInputs){
|
||||
input.addEventListener('input', function() {
|
||||
removeFormErrors(input, true);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -84,7 +84,7 @@
|
|||
|
||||
<div class="margin-bottom-3">
|
||||
<button
|
||||
id="check-avail-for-alt-domains"
|
||||
id="validate-alt-domains-availability"
|
||||
type="button"
|
||||
class="usa-button usa-button--outline"
|
||||
validate-for="{{ forms.1.requested_domain.auto_id }}"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue