This commit is contained in:
zandercymatics 2024-04-03 15:23:02 -06:00
parent 6d13614521
commit e4c83751bf
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
3 changed files with 48 additions and 3 deletions

View file

@ -15,7 +15,7 @@ from registrar.utility.errors import (
SecurityEmailError, SecurityEmailError,
SecurityEmailErrorCodes, SecurityEmailErrorCodes,
) )
from django.core.validators import RegexValidator, MaxLengthValidator
from ..models import Contact, DomainInformation, Domain from ..models import Contact, DomainInformation, Domain
from .common import ( from .common import (
ALGORITHM_CHOICES, ALGORITHM_CHOICES,
@ -31,7 +31,18 @@ logger = logging.getLogger(__name__)
class DomainAddUserForm(forms.Form): class DomainAddUserForm(forms.Form):
"""Form for adding a user to a domain.""" """Form for adding a user to a domain."""
email = forms.EmailField(label="Email") email = forms.EmailField(
label="Email",
max_length=254,
error_messages={"invalid": ("Enter your email address in the required format, like name@example.com.")},
# This validator should exist in the event that a preexisting field is of invalid length
validators=[
MaxLengthValidator(
254,
message="Response must be less than 254 characters.",
)
],
)
def clean(self): def clean(self):
"""clean form data by lowercasing email""" """clean form data by lowercasing email"""
@ -193,6 +204,8 @@ class ContactForm(forms.ModelForm):
# take off maxlength attribute for the phone number field # take off maxlength attribute for the phone number field
# which interferes with out input_with_errors template tag # which interferes with out input_with_errors template tag
self.fields["phone"].widget.attrs.pop("maxlength", None) self.fields["phone"].widget.attrs.pop("maxlength", None)
max = self.fields["email"].widget.attrs["maxlength"]
print(f"what is the max? {max}")
for field_name in self.required: for field_name in self.required:
self.fields[field_name].required = True self.fields[field_name].required = True
@ -291,10 +304,18 @@ class DomainSecurityEmailForm(forms.Form):
security_email = forms.EmailField( security_email = forms.EmailField(
label="Security email (optional)", label="Security email (optional)",
max_length=254,
required=False, required=False,
error_messages={ error_messages={
"invalid": str(SecurityEmailError(code=SecurityEmailErrorCodes.BAD_DATA)), "invalid": str(SecurityEmailError(code=SecurityEmailErrorCodes.BAD_DATA)),
}, },
# This validator should exist in the event that a preexisting field is of invalid length
validators=[
MaxLengthValidator(
254,
message="Response must be less than 254 characters.",
)
],
) )

View file

@ -369,7 +369,15 @@ class AuthorizingOfficialForm(RegistrarForm):
) )
email = forms.EmailField( email = forms.EmailField(
label="Email", label="Email",
max_length=254,
error_messages={"invalid": ("Enter an email address in the required format, like name@example.com.")}, error_messages={"invalid": ("Enter an email address in the required format, like name@example.com.")},
# This validator should exist in the event that a preexisting field is of invalid length
validators=[
MaxLengthValidator(
254,
message="Response must be less than 254 characters.",
)
],
) )
@ -566,7 +574,15 @@ class YourContactForm(RegistrarForm):
) )
email = forms.EmailField( email = forms.EmailField(
label="Email", label="Email",
max_length=254,
error_messages={"invalid": ("Enter your email address in the required format, like name@example.com.")}, error_messages={"invalid": ("Enter your email address in the required format, like name@example.com.")},
# This validator should exist in the event that a preexisting field is of invalid length
validators=[
MaxLengthValidator(
254,
message="Response must be less than 254 characters.",
)
],
) )
phone = PhoneNumberField( phone = PhoneNumberField(
label="Phone", label="Phone",
@ -621,10 +637,18 @@ class OtherContactsForm(RegistrarForm):
) )
email = forms.EmailField( email = forms.EmailField(
label="Email", label="Email",
max_length=254,
error_messages={ error_messages={
"required": ("Enter an email address in the required format, like name@example.com."), "required": ("Enter an email address in the required format, like name@example.com."),
"invalid": ("Enter an email address in the required format, like name@example.com."), "invalid": ("Enter an email address in the required format, like name@example.com."),
}, },
# This validator should exist in the event that a preexisting field is of invalid length
validators=[
MaxLengthValidator(
254,
message="Response must be less than 254 characters.",
)
],
) )
phone = PhoneNumberField( phone = PhoneNumberField(
label="Phone", label="Phone",

View file

@ -76,7 +76,7 @@ error messages, if necessary.
</div> </div>
{% endif %} {% endif %}
{% if widget.attrs.maxlength %} {% if widget.attrs.maxlength and show_max_length %}
<span <span
id="{{ widget.attrs.id }}__message" id="{{ widget.attrs.id }}__message"
class="usa-character-count__message" class="usa-character-count__message"