Merge pull request #1375 from cisagov/es/984-refine-error-messages

#984: Update form error messages on domain management contacts
This commit is contained in:
Erin Song 2023-11-21 12:51:36 -08:00 committed by GitHub
commit 5ae14c964a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 1 deletions

View file

@ -5,6 +5,7 @@ from .domain import (
DomainSecurityEmailForm,
DomainOrgNameAddressForm,
ContactForm,
AuthorizingOfficialContactForm,
DomainDnssecForm,
DomainDsdataFormset,
DomainDsdataForm,

View file

@ -154,6 +154,40 @@ class ContactForm(forms.ModelForm):
for field_name in self.required:
self.fields[field_name].required = True
# Set custom error messages
self.fields["first_name"].error_messages = {"required": "Enter your first name / given name."}
self.fields["last_name"].error_messages = {"required": "Enter your last name / family name."}
self.fields["title"].error_messages = {
"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 name@example.com."
}
self.fields["phone"].error_messages = {"required": "Enter your phone number."}
class AuthorizingOfficialContactForm(ContactForm):
"""Form for updating authorizing official contacts."""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# Set custom error messages
self.fields["first_name"].error_messages = {
"required": "Enter the first name / given name of your authorizing official."
}
self.fields["last_name"].error_messages = {
"required": "Enter the last name / family name of your authorizing official."
}
self.fields["title"].error_messages = {
"required": "Enter the title or role your authorizing official has in your \
organization (e.g., Chief Information Officer)."
}
self.fields["email"].error_messages = {
"required": "Enter an email address in the required format, like name@example.com."
}
self.fields["phone"].error_messages = {"required": "Enter a phone number for your authorizing official."}
class DomainSecurityEmailForm(forms.Form):
"""Form for adding or editing a security email to a domain."""

View file

@ -37,6 +37,7 @@ from registrar.models.utility.contact_error import ContactError
from ..forms import (
ContactForm,
AuthorizingOfficialContactForm,
DomainOrgNameAddressForm,
DomainAddUserForm,
DomainSecurityEmailForm,
@ -186,7 +187,7 @@ class DomainAuthorizingOfficialView(DomainFormBaseView):
model = Domain
template_name = "domain_authorizing_official.html"
context_object_name = "domain"
form_class = ContactForm
form_class = AuthorizingOfficialContactForm
def get_form_kwargs(self, *args, **kwargs):
"""Add domain_info.authorizing_official instance to make a bound form."""