Variable cleanup and function refactoring

This commit is contained in:
Rebecca Hsieh 2024-01-25 11:58:38 -08:00
parent dac472cab2
commit 694ae50e34
No known key found for this signature in database
2 changed files with 16 additions and 16 deletions

View file

@ -212,23 +212,20 @@ function handleValidationClick(e) {
} }
function handleFormsetValidationClick(e) { function handleFormsetValidationClick(e, availabilityButton) {
// Check availability for alternative domains
const alternativeDomainsAvailability = document.getElementById('check-avail-for-alt-domains');
// Collect input IDs from the repeatable forms // Collect input IDs from the repeatable forms
let inputIds = Array.from(document.querySelectorAll('.repeatable-form input')).map(input => input.id); let inputs = Array.from(document.querySelectorAll('.repeatable-form input'))
// Run validators for each input // Run validators for each input
inputIds.forEach(inputId => { inputs.forEach(input => {
const input = document.getElementById(inputId);
runValidators(input); runValidators(input);
}); });
// Set the validate-for attribute on the button with the collected input IDs // Set the validate-for attribute on the button with the collected input IDs
// Not needed for functionality but nice for accessibility // Not needed for functionality but nice for accessibility
alternativeDomainsAvailability.setAttribute('validate-for', inputIds.join(', ')); inputs = inputs.map(input => input.id).join(', ');
availabilityButton.setAttribute('validate-for', inputs);
} }
// <<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>> // <<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>>
@ -256,7 +253,9 @@ function handleFormsetValidationClick(e) {
for(const button of activatesValidation) { for(const button of activatesValidation) {
// Adds multi-field validation for alternative domains // Adds multi-field validation for alternative domains
if (button === alternativeDomainsAvailability) { if (button === alternativeDomainsAvailability) {
button.addEventListener('click', handleFormsetValidationClick); button.addEventListener('click', (e) => {
handleFormsetValidationClick(e, alternativeDomainsAvailability)
});
} else { } else {
button.addEventListener('click', handleValidationClick); button.addEventListener('click', handleValidationClick);
} }

View file

@ -173,12 +173,13 @@ class Domain(TimeStampedModel, DomainHelper):
@classmethod @classmethod
def available(cls, domain: str) -> bool: def available(cls, domain: str) -> bool:
"""Check if a domain is available.""" return True
if not cls.string_could_be_domain(domain): # """Check if a domain is available."""
raise ValueError("Not a valid domain: %s" % str(domain)) # if not cls.string_could_be_domain(domain):
domain_name = domain.lower() # raise ValueError("Not a valid domain: %s" % str(domain))
req = commands.CheckDomain([domain_name]) # domain_name = domain.lower()
return registry.send(req, cleaned=True).res_data[0].avail # req = commands.CheckDomain([domain_name])
# return registry.send(req, cleaned=True).res_data[0].avail
@classmethod @classmethod
def registered(cls, domain: str) -> bool: def registered(cls, domain: str) -> bool: