Skip to content

Commit

Permalink
Merge pull request #2891 from cisagov/dk/2777-update-messaging
Browse files Browse the repository at this point in the history
#2777: updated error messages for zip codes and email addresses
  • Loading branch information
dave-kennedy-ecs authored Oct 13, 2024
2 parents a1d9904 + da96454 commit ffd4d7f
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 15 deletions.
14 changes: 10 additions & 4 deletions src/registrar/forms/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ class DomainAddUserForm(forms.Form):
email = forms.EmailField(
label="Email",
max_length=None,
error_messages={"invalid": ("Enter your email address in the required format, like [email protected].")},
error_messages={
"invalid": ("Enter an email address in the required format, like [email protected]."),
"required": ("Enter an email address in the required format, like [email protected]."),
},
validators=[
MaxLengthValidator(
320,
Expand Down Expand Up @@ -285,7 +288,7 @@ def __init__(self, *args, **kwargs):
"required": "Enter your title or role in your organization (e.g., Chief Information Officer)"
}
self.fields["email"].error_messages = {
"required": "Enter your email address in the required format, like [email protected]."
"required": "Enter an email address in the required format, like [email protected]."
}
self.fields["phone"].error_messages["required"] = "Enter your phone number."
self.domainInfo = None
Expand Down Expand Up @@ -342,7 +345,7 @@ def __init__(self, *args, **kwargs):
"required": "Enter your title or role in your organization (e.g., Chief Information Officer)"
}
self.fields["email"].error_messages = {
"required": "Enter your email address in the required format, like [email protected]."
"required": "Enter an email address in the required format, like [email protected]."
}
self.fields["phone"].error_messages["required"] = "Enter your phone number."
self.domainInfo = None
Expand Down Expand Up @@ -458,9 +461,12 @@ class DomainOrgNameAddressForm(forms.ModelForm):
validators=[
RegexValidator(
"^[0-9]{5}(?:-[0-9]{4})?$|^$",
message="Enter a zip code in the required format, like 12345 or 12345-6789.",
message="Enter a 5-digit or 9-digit zip code, like 12345 or 12345-6789.",
)
],
error_messages={
"required": "Enter a 5-digit or 9-digit zip code, like 12345 or 12345-6789.",
},
)

class Meta:
Expand Down
12 changes: 8 additions & 4 deletions src/registrar/forms/domain_request_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ class OrganizationContactForm(RegistrarForm):
validators=[
RegexValidator(
"^[0-9]{5}(?:-[0-9]{4})?$|^$",
message="Enter a zip code in the form of 12345 or 12345-6789.",
message="Enter a 5-digit or 9-digit zip code, like 12345 or 12345-6789.",
)
],
error_messages={"required": ("Enter a zip code in the form of 12345 or 12345-6789.")},
error_messages={"required": ("Enter a 5-digit or 9-digit zip code, like 12345 or 12345-6789.")},
)
urbanization = forms.CharField(
required=False,
Expand Down Expand Up @@ -233,7 +233,10 @@ def from_database(cls, obj):
email = forms.EmailField(
label="Email",
max_length=None,
error_messages={"invalid": ("Enter an email address in the required format, like [email protected].")},
error_messages={
"invalid": ("Enter an email address in the required format, like [email protected]."),
"required": ("Enter an email address in the required format, like [email protected]."),
},
validators=[
MaxLengthValidator(
320,
Expand Down Expand Up @@ -610,7 +613,8 @@ class CisaRepresentativeForm(BaseDeletableRegistrarForm):
max_length=None,
required=False,
error_messages={
"invalid": ("Enter your representative’s email address in the required format, like [email protected]."),
"invalid": ("Enter an email address in the required format, like [email protected]."),
"required": ("Enter an email address in the required format, like [email protected]."),
},
validators=[
MaxLengthValidator(
Expand Down
6 changes: 5 additions & 1 deletion src/registrar/forms/portfolio.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ class PortfolioOrgAddressForm(forms.ModelForm):
validators=[
RegexValidator(
"^[0-9]{5}(?:-[0-9]{4})?$|^$",
message="Enter a zip code in the required format, like 12345 or 12345-6789.",
message="Enter a 5-digit or 9-digit zip code, like 12345 or 12345-6789.",
)
],
error_messages={
"required": "Enter a 5-digit or 9-digit zip code, like 12345 or 12345-6789.",
},
)

class Meta:
Expand All @@ -38,6 +41,7 @@ class Meta:
"state_territory": {
"required": "Select the state, territory, or military post where your organization is located."
},
"zipcode": {"required": "Enter a 5-digit or 9-digit zip code, like 12345 or 12345-6789."},
}
widgets = {
# We need to set the required attributed for State/territory
Expand Down
2 changes: 1 addition & 1 deletion src/registrar/forms/user_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def __init__(self, *args, **kwargs):
"required": "Enter your title or role in your organization (e.g., Chief Information Officer)"
}
self.fields["email"].error_messages = {
"required": "Enter your email address in the required format, like [email protected]."
"required": "Enter an email address in the required format, like [email protected]."
}
self.fields["phone"].error_messages["required"] = "Enter your phone number."

Expand Down
2 changes: 1 addition & 1 deletion src/registrar/templates/domain_org_name_address.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ <h1>Organization</h1>

{% input_with_errors form.state_territory %}

{% with add_class="usa-input--small" sublabel_text="Enter a zip code in the required format, like 12345 or 12345-6789." %}
{% with add_class="usa-input--small" sublabel_text="Enter a 5-digit or 9-digit zip code, like 12345 or 12345-6789." %}
{% input_with_errors form.zipcode %}
{% endwith %}

Expand Down
2 changes: 1 addition & 1 deletion src/registrar/templates/domain_request_org_contact.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ <h2>What is the name and mailing address of the organization you represent?</h2>

{% input_with_errors forms.0.state_territory %}

{% with add_class="usa-input--small" sublabel_text="Enter a zip code in the required format, like 12345 or 12345-6789." %}
{% with add_class="usa-input--small" sublabel_text="Enter a 5-digit or 9-digit zip code, like 12345 or 12345-6789." %}
{% input_with_errors forms.0.zipcode %}
{% endwith %}

Expand Down
2 changes: 1 addition & 1 deletion src/registrar/templates/portfolio_organization.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ <h4 class="read-only-label">Organization name</h4>
{% input_with_errors form.address_line2 %}
{% input_with_errors form.city %}
{% input_with_errors form.state_territory %}
{% with add_class="usa-input--small" sublabel_text="Enter a zip code in the required format, like 12345 or 12345-6789." %}
{% with add_class="usa-input--small" sublabel_text="Enter a 5-digit or 9-digit zip code, like 12345 or 12345-6789." %}
{% input_with_errors form.zipcode %}
{% endwith %}
<button type="submit" class="usa-button">
Expand Down
2 changes: 1 addition & 1 deletion src/registrar/tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_org_contact_zip_invalid(self):
form = OrganizationContactForm(data={"zipcode": "nah"})
self.assertEqual(
form.errors["zipcode"],
["Enter a zip code in the form of 12345 or 12345-6789."],
["Enter a 5-digit or 9-digit zip code, like 12345 or 12345-6789."],
)

def test_org_contact_zip_valid(self):
Expand Down
2 changes: 1 addition & 1 deletion src/registrar/utility/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ class SecurityEmailError(Exception):
"""

_error_mapping = {
SecurityEmailErrorCodes.BAD_DATA: ("Enter an email address in the required format, " "like [email protected]."),
SecurityEmailErrorCodes.BAD_DATA: ("Enter an email address in the required format, like [email protected]."),
}

def __init__(self, *args, code=None, **kwargs):
Expand Down

0 comments on commit ffd4d7f

Please sign in to comment.