diff --git a/src/registrar/assets/js/get-gov.js b/src/registrar/assets/js/get-gov.js index 540b167eb..09e67fbc1 100644 --- a/src/registrar/assets/js/get-gov.js +++ b/src/registrar/assets/js/get-gov.js @@ -919,36 +919,43 @@ function hideDeletedForms() { } function showInputOnErrorFields(){ - let fullNameButtonClicked = false document.addEventListener('DOMContentLoaded', function() { - document.querySelectorAll('[id$="__edit-button"]').forEach(function(button) { - let fieldIdParts = button.id.split("__") - if (fieldIdParts && fieldIdParts.length > 0){ - let fieldName = fieldIdParts[0] + let form = document.querySelector('.main-content-finish-profile'); + // Get all input elements within the form + let inputs = form ? form.querySelectorAll('input') : null; + if (!inputs) { + return null; + } - // Check if an error message exists for the given field - let errorMessage = document.querySelector(`#id_${fieldName}__error-message`); - if (errorMessage) { - - // Show the input field of the field that errored out - button.click() + let fullNameButtonClicked = false + inputs.forEach(function(input) { + let fieldName = input.name; + let errorMessage = document.querySelector(`#id_${fieldName}__error-message`); + if (!fieldName || !errorMessage) { + return null; + } - // If either the full_name field errors out, - // or if any of its associated fields do - show all name related fields. - let nameFields = ["first_name", "middle_name", "last_name"] - if (nameFields.includes(fieldName) && !fullNameButtonClicked){ - // Click the full name button if any of its related fields error out - fullNameButton = document.querySelector("#full_name__edit-button") - if (fullNameButton) { - fullNameButton.click() - fullNameButtonClicked = true - } - } + let editButton = document.querySelector(`#${fieldName}__edit-button`); + console.log(`edit button is ${editButton} vs id #${fieldName}__edit-button`) + if (editButton){ + // Show the input field of the field that errored out + editButton.click(); + } + + // If either the full_name field errors out, + // or if any of its associated fields do - show all name related fields. + let nameFields = ["first_name", "middle_name", "last_name"]; + if (nameFields.includes(fieldName) && !fullNameButtonClicked){ + // Click the full name button if any of its related fields error out + fullNameButton = document.querySelector("#full_name__edit-button"); + if (fullNameButton) { + fullNameButton.click(); + fullNameButtonClicked = true; } } }); }); - } + }; // Hookup all edit buttons to the `handleEditButtonClick` function setupListener(); diff --git a/src/registrar/templates/finish_profile_setup.html b/src/registrar/templates/finish_profile_setup.html index 80ac9f09f..0b958c24c 100644 --- a/src/registrar/templates/finish_profile_setup.html +++ b/src/registrar/templates/finish_profile_setup.html @@ -11,7 +11,7 @@
-
+
{% comment %} Form success messages. @@ -44,7 +44,7 @@

Finish setting up your profile

- We require + We require that you maintain accurate contact information. The details you provide will only be used to support the administration of .gov and won’t be made public.

@@ -72,18 +72,20 @@ {% input_with_errors form.first_name %} {% endwith %} - {% with group_classes="usa-form-readonly padding-top-2" %} + {% with group_classes="usa-form-readonly padding-top-2" %} {% input_with_errors form.middle_name %} {% endwith %} - {% with group_classes="usa-form-readonly padding-top-2" %} + {% with group_classes="usa-form-readonly padding-top-2" %} {% input_with_errors form.last_name %} {% endwith %}
{# This field doesn't have the readonly button but it has common design elements from it #} - {% with show_readonly=True add_class="display-none" group_classes="usa-form-readonly padding-top-2 bold-usa-label" sublabel_text=email_sublabel_text %} - {% input_with_errors form.email %} + {% with show_readonly=True group_classes="usa-form-readonly padding-top-2 bold-usa-label" %} + {% with target_blank="true" sublabel_text=email_sublabel_text add_class="display-none" %} + {% input_with_errors form.email %} + {% endwith %} {% endwith %} {% with show_edit_button=True show_readonly=True group_classes="usa-form-readonly padding-top-2" %} diff --git a/src/registrar/views/utility/mixins.py b/src/registrar/views/utility/mixins.py index 62a376511..774507296 100644 --- a/src/registrar/views/utility/mixins.py +++ b/src/registrar/views/utility/mixins.py @@ -400,7 +400,7 @@ class UserProfilePermission(PermissionsLoginMixin): return False # If we are given a pk in the request, do checks on it - given_contact_pk = self.kwargs["pk"] + given_contact_pk = self.kwargs.get("pk", None) if given_contact_pk: # Grab the user in the DB to do a full object comparision, not just on ids