fixed the 'other' problem in requesting entity form

This commit is contained in:
David Kennedy 2025-01-15 12:44:47 -05:00
parent fabeddaa61
commit 74ef30b52d
No known key found for this signature in database
GPG key ID: 6528A5386E66B96B
2 changed files with 10 additions and 9 deletions

View file

@ -38,11 +38,6 @@ export function handleRequestingEntityFieldset() {
requestingNewSuborganization.value === "True" ? showElement(suborgDetailsContainer) : hideElement(suborgDetailsContainer); requestingNewSuborganization.value === "True" ? showElement(suborgDetailsContainer) : hideElement(suborgDetailsContainer);
} }
// Add fake "other" option to sub_organization select
if (select && !Array.from(select.options).some(option => option.value === "other")) {
select.add(new Option(subOrgCreateNewOption, "other"));
}
if (requestingNewSuborganization.value === "True") { if (requestingNewSuborganization.value === "True") {
select.value = "other"; select.value = "other";
} }

View file

@ -63,13 +63,19 @@ class RequestingEntityForm(RegistrarForm):
) )
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
"""Override of init to add the suborganization queryset""" """Override of init to add the suborganization queryset and 'other' option"""
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
if self.domain_request.portfolio: if self.domain_request.portfolio:
self.fields["sub_organization"].queryset = Suborganization.objects.filter( # Fetch the queryset for the portfolio
portfolio=self.domain_request.portfolio queryset = Suborganization.objects.filter(portfolio=self.domain_request.portfolio)
) # set the queryset appropriately so that post can validate against queryset
self.fields["sub_organization"].queryset = queryset
# Modify the choices to include "other" so that form can display options properly
self.fields["sub_organization"].choices = [("", "--Select--")] + [
(obj.id, str(obj)) for obj in queryset
] + [("other", "Other (enter your suborganization manually)")]
def clean_sub_organization(self): def clean_sub_organization(self):
"""On suborganization clean, set the suborganization value to None if the user is requesting """On suborganization clean, set the suborganization value to None if the user is requesting