Exclude blank fields

This commit is contained in:
zandercymatics 2024-01-09 14:40:53 -07:00
parent 45e994ea05
commit 7045e5dcad
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
2 changed files with 14 additions and 3 deletions

View file

@ -134,10 +134,19 @@ function _checkDomainAvailability(el) {
const callback = (response) => {
toggleInputValidity(el, (response && response.available), msg=response.message);
announce(el.id, response.message);
// Determines if we ignore the field if it is just blank
ignore_blank = el.classList.contains("blank-ok")
if (el.validity.valid) {
el.classList.add('usa-input--success');
// use of `parentElement` due to .gov inputs being wrapped in www/.gov decoration
inlineToast(el.parentElement, el.id, SUCCESS, response.message);
} else if (ignore_blank && response.code == "required"){
// Visually remove the error
error = "usa-input--error"
if (el.classList.contains(error)){
el.classList.remove(error)
}
} else {
inlineToast(el.parentElement, el.id, ERROR, response.message);
}

View file

@ -73,9 +73,11 @@
{# attr_validate / validate="domain" invokes code in get-gov.js #}
{# attr_auto_validate likewise triggers behavior in get-gov.js #}
{% with append_gov=True attr_validate="domain" attr_auto_validate=True %}
{% for form in forms.1 %}
{% input_with_errors form.alternative_domain %}
{% endfor %}
{% with add_class="blank-ok" %}
{% for form in forms.1 %}
{% input_with_errors form.alternative_domain %}
{% endfor %}
{% endwith %}
{% endwith %}
{% endwith %}