Add custom errors for authorizing official

This commit is contained in:
Erin 2023-11-20 14:06:44 -08:00
parent cd6809c9f7
commit d2e6e083f3
No known key found for this signature in database
GPG key ID: 1CAD275313C62460
3 changed files with 23 additions and 1 deletions

View file

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

View file

@ -148,6 +148,9 @@ class ContactForm(forms.ModelForm):
for field_name in self.required:
self.fields[field_name].required = True
# Set custom form label
self.fields["middle_name"].label = "Middle name (optional)"
# 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.'}
@ -159,6 +162,23 @@ class ContactForm(forms.ModelForm):
}
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 this contact.'}
self.fields["last_name"].error_messages = {'required': 'Enter the last name / family name of this contact.'}
self.fields["title"].error_messages = {
'required': 'Enter the title or role in your organization of this contact \
(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 this contact.'}
class DomainSecurityEmailForm(forms.Form):
"""Form for adding or editing a security email to a domain."""

View file

@ -33,6 +33,7 @@ from registrar.models.utility.contact_error import ContactError
from ..forms import (
ContactForm,
AuthorizingOfficialContactForm,
DomainOrgNameAddressForm,
DomainAddUserForm,
DomainSecurityEmailForm,
@ -182,7 +183,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."""