fix bug with form save

Since cleaned data was not being touched, the form was not resetting values correctly
This commit is contained in:
zandercymatics 2024-10-30 14:20:26 -06:00
parent a94a5b2075
commit c465b7fb67
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
4 changed files with 20 additions and 13 deletions

View file

@ -2789,7 +2789,6 @@ document.addEventListener('DOMContentLoaded', function() {
subOrgSelect.add(fakeOption);
}
console.log(isRequestingSuborganization.value)
if (isRequestingSuborganization.value === "True") {
subOrgSelect.value = "other"
}

View file

@ -111,7 +111,9 @@ class RequestingEntityForm(RegistrarForm):
# 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

View file

@ -1717,7 +1717,6 @@ class TestRequestingEntity(WebTest):
self.assertContains(response, "Who will use the domain youre 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"] = ""

View file

@ -594,25 +594,32 @@ class RequestingEntity(DomainRequestWizard):
"""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)