From 7045e5dcadf1efd206854af4f381391fde50c9ae Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Tue, 9 Jan 2024 14:40:53 -0700 Subject: [PATCH] Exclude blank fields --- src/registrar/assets/js/get-gov.js | 9 +++++++++ src/registrar/templates/application_dotgov_domain.html | 8 +++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/registrar/assets/js/get-gov.js b/src/registrar/assets/js/get-gov.js index a2a99e104..92b6a1e46 100644 --- a/src/registrar/assets/js/get-gov.js +++ b/src/registrar/assets/js/get-gov.js @@ -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); } diff --git a/src/registrar/templates/application_dotgov_domain.html b/src/registrar/templates/application_dotgov_domain.html index bd3c4a473..ab5504264 100644 --- a/src/registrar/templates/application_dotgov_domain.html +++ b/src/registrar/templates/application_dotgov_domain.html @@ -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 %}