Skip to content

Commit

Permalink
fix bug with form save
Browse files Browse the repository at this point in the history
Since cleaned data was not being touched, the form was not resetting values correctly
  • Loading branch information
zandercymatics committed Oct 30, 2024
1 parent a94a5b2 commit c465b7f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
1 change: 0 additions & 1 deletion src/registrar/assets/js/get-gov.js
Original file line number Diff line number Diff line change
Expand Up @@ -2789,7 +2789,6 @@ document.addEventListener('DOMContentLoaded', function() {
subOrgSelect.add(fakeOption);
}

console.log(isRequestingSuborganization.value)
if (isRequestingSuborganization.value === "True") {
subOrgSelect.value = "other"
}
Expand Down
4 changes: 3 additions & 1 deletion src/registrar/forms/domain_request_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ def clean(self):

# Get the value of the yes/no checkbox from RequestingEntityYesNoForm.
# Since self.data stores this as a string, we need to convert "True" => True.
requesting_entity_is_suborganization = self.data.get("portfolio_requesting_entity-requesting_entity_is_suborganization")
requesting_entity_is_suborganization = self.data.get(
"portfolio_requesting_entity-requesting_entity_is_suborganization"
)
if requesting_entity_is_suborganization == "True":
if is_requesting_new_suborganization:
# Validate custom suborganization fields
Expand Down
1 change: 0 additions & 1 deletion src/registrar/tests/test_views_portfolio.py
Original file line number Diff line number Diff line change
Expand Up @@ -1717,7 +1717,6 @@ def test_requesting_entity_page_new_suborg_submission(self):
self.assertContains(response, "Who will use the domain you’re requesting?")
form = response.forms[0]

# Test selecting an existing suborg
form["portfolio_requesting_entity-requesting_entity_is_suborganization"] = True
form["portfolio_requesting_entity-is_requesting_new_suborganization"] = True
form["portfolio_requesting_entity-sub_organization"] = ""
Expand Down
27 changes: 17 additions & 10 deletions src/registrar/views/domain_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,25 +594,32 @@ def save(self, forms: list):
"""Override of save to clear or associate certain suborganization data
depending on what the user wishes to do. For instance, we want to add a suborganization
if the user selects one."""
yesno_form = forms[0]
requesting_entity_form = forms[1]

yesno_cleaned_data = yesno_form.cleaned_data
requesting_entity_is_suborganization = yesno_cleaned_data.get("requesting_entity_is_suborganization")

cleaned_data = requesting_entity_form.cleaned_data
requesting_entity_is_suborganization = cleaned_data.get("requesting_entity_is_suborganization")
sub_organization = cleaned_data.get("sub_organization")
requested_suborganization = cleaned_data.get("requested_suborganization")

if requesting_entity_is_suborganization and (sub_organization or requested_suborganization):
# Cleanup the organization name field, as this isn't for suborganizations.
self.domain_request.organization_name = None
self.domain_request.sub_organization = sub_organization
requesting_entity_form.cleaned_data.update({"organization_name": None})
else:
# If the user doesn't intend to create a suborg, simply don't make one and do some data cleanup
if self.domain_request.portfolio:
self.domain_request.organization_name = self.domain_request.portfolio.organization_name

self.domain_request.sub_organization = None
self.domain_request.requested_suborganization = None
self.domain_request.suborganization_city = None
self.domain_request.suborganization_state_territory = None
requesting_entity_form.cleaned_data.update(
{
"organization_name": (
self.domain_request.portfolio.organization_name if self.domain_request.portfolio else None
),
"sub_organization": None,
"requested_suborganization": None,
"suborganization_city": None,
"suborganization_state_territory": None,
}
)

super().save(forms)

Expand Down

0 comments on commit c465b7f

Please sign in to comment.