diff --git a/src/registrar/assets/js/get-gov-admin.js b/src/registrar/assets/js/get-gov-admin.js index 277f81b72..f8bba4967 100644 --- a/src/registrar/assets/js/get-gov-admin.js +++ b/src/registrar/assets/js/get-gov-admin.js @@ -807,10 +807,8 @@ function initializeWidgetOnList(list, parentId) { if (organizationType.value !== "federal") { organizationType.value = "federal"; } - // Set the SO field }else if (selectedText === "Non-Federal Agency" && organizationType.value === "federal") { organizationType.value = ""; - // Set the SO field } // There isn't a senior official associated with null records and non federal agencies @@ -830,6 +828,8 @@ function initializeWidgetOnList(list, parentId) { .then(response => response.json()) .then(data => { if (data.error) { + // Clear the field if the SO doesn't exist + $seniorOfficial.val("").trigger("change"); console.error('Error in AJAX call: ' + data.error); return; } @@ -837,7 +837,8 @@ function initializeWidgetOnList(list, parentId) { let seniorOfficialId = data.id; let seniorOfficialName = [data.first_name, data.last_name].join(" "); if (!seniorOfficialId || !seniorOfficialName || !seniorOfficialName.trim()){ - console.error("Could not assign current Senior Official: no values found.") + // Clear the field if the SO doesn't exist + $seniorOfficial.val("").trigger("change"); return; } diff --git a/src/registrar/models/portfolio.py b/src/registrar/models/portfolio.py index 06b01e672..e705aaa83 100644 --- a/src/registrar/models/portfolio.py +++ b/src/registrar/models/portfolio.py @@ -110,3 +110,12 @@ class Portfolio(TimeStampedModel): def __str__(self) -> str: return f"{self.organization_name}" + + def save(self, *args, **kwargs): + """Save override for custom properties""" + + # We can't have urbanization if the state isn't puerto rico + if self.state_territory != self.StateTerritoryChoices.PUERTO_RICO and self.urbanization: + self.urbanization = None + + super().save(*args, **kwargs) diff --git a/src/registrar/views/utility/api_views.py b/src/registrar/views/utility/api_views.py index a1639529f..f1cb7c75f 100644 --- a/src/registrar/views/utility/api_views.py +++ b/src/registrar/views/utility/api_views.py @@ -25,6 +25,12 @@ def get_senior_official_from_federal_agency_json(request): if agency and senior_official: # Convert the agency object to a dictionary so_dict = model_to_dict(senior_official) + + # The phone number field isn't json serializable, so we + # convert this to a string first if it exists. + if "phone" in so_dict and so_dict.get("phone"): + so_dict["phone"] = str(so_dict["phone"]) + return JsonResponse(so_dict) else: return JsonResponse({"error": "Senior Official not found"}, status=404)