Review feedback: more required instructions

This commit is contained in:
Neil Martinsen-Burrell 2023-01-06 13:32:26 -06:00
parent 29d8f4b23d
commit beb9a298d4
No known key found for this signature in database
GPG key ID: 6A3C818CC10D0184
5 changed files with 39 additions and 8 deletions

View file

@ -101,9 +101,10 @@ class OrganizationContactForm(RegistrarForm):
federal_agency = forms.ChoiceField(
label="Federal agency",
# not required because this field won't be filled out unless
# it is a federal agency.
# it is a federal agency. Use clean to check programatically
# if it has been filled in when required.
required=False,
choices=DomainApplication.AGENCY_CHOICES,
choices=[("", "--Select--")] + DomainApplication.AGENCY_CHOICES,
label_suffix=REQUIRED_SUFFIX,
)
organization_name = forms.CharField(
@ -138,6 +139,18 @@ class OrganizationContactForm(RegistrarForm):
label="Urbanization (Puerto Rico only)",
)
def clean_federal_agency(self):
"""Require something to be selected when this is a federal agency."""
federal_agency = self.cleaned_data.get("federal_agency", None)
# need the wizard object to know if this is federal
context = self.get_context()
print(context)
if wizard._is_federal():
if not federal_agency:
# no answer was selected
raise forms.ValidationError("Please select your federal agency.", code="required")
return federal_agency
class AuthorizingOfficialForm(RegistrarForm):
def to_database(self, obj):