mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-01 23:42:17 +02:00
Variable cleanup and function refactoring
This commit is contained in:
parent
dac472cab2
commit
694ae50e34
2 changed files with 16 additions and 16 deletions
|
@ -212,23 +212,20 @@ function handleValidationClick(e) {
|
|||
}
|
||||
|
||||
|
||||
function handleFormsetValidationClick(e) {
|
||||
// Check availability for alternative domains
|
||||
|
||||
const alternativeDomainsAvailability = document.getElementById('check-avail-for-alt-domains');
|
||||
|
||||
function handleFormsetValidationClick(e, availabilityButton) {
|
||||
|
||||
// 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
|
||||
inputIds.forEach(inputId => {
|
||||
const input = document.getElementById(inputId);
|
||||
inputs.forEach(input => {
|
||||
runValidators(input);
|
||||
});
|
||||
|
||||
// Set the validate-for attribute on the button with the collected input IDs
|
||||
// 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) {
|
||||
// Adds multi-field validation for alternative domains
|
||||
if (button === alternativeDomainsAvailability) {
|
||||
button.addEventListener('click', handleFormsetValidationClick);
|
||||
button.addEventListener('click', (e) => {
|
||||
handleFormsetValidationClick(e, alternativeDomainsAvailability)
|
||||
});
|
||||
} else {
|
||||
button.addEventListener('click', handleValidationClick);
|
||||
}
|
||||
|
|
|
@ -173,12 +173,13 @@ class Domain(TimeStampedModel, DomainHelper):
|
|||
|
||||
@classmethod
|
||||
def available(cls, domain: str) -> bool:
|
||||
"""Check if a domain is available."""
|
||||
if not cls.string_could_be_domain(domain):
|
||||
raise ValueError("Not a valid domain: %s" % str(domain))
|
||||
domain_name = domain.lower()
|
||||
req = commands.CheckDomain([domain_name])
|
||||
return registry.send(req, cleaned=True).res_data[0].avail
|
||||
return True
|
||||
# """Check if a domain is available."""
|
||||
# if not cls.string_could_be_domain(domain):
|
||||
# raise ValueError("Not a valid domain: %s" % str(domain))
|
||||
# domain_name = domain.lower()
|
||||
# req = commands.CheckDomain([domain_name])
|
||||
# return registry.send(req, cleaned=True).res_data[0].avail
|
||||
|
||||
@classmethod
|
||||
def registered(cls, domain: str) -> bool:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue