This commit is contained in:
zandercymatics 2024-05-10 08:33:10 -06:00
parent 75499337e0
commit dd9df90fb4
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
5 changed files with 55 additions and 13 deletions

View file

@ -1,11 +1,15 @@
from django import forms
from phonenumber_field.modelfields import PhoneNumberField # type: ignore
from phonenumber_field.formfields import PhoneNumberField # type: ignore
from django.core.validators import MaxLengthValidator
class ContactForm(forms.Form):
"""Form for adding or editing a contact"""
def __init__(self, *args, **kwargs):
kwargs.setdefault("label_suffix", "")
super(ContactForm, self).__init__(*args, **kwargs)
first_name = forms.CharField(
label="First name / given name",
error_messages={"required": "Enter your first name / given name."},

View file

@ -16,7 +16,6 @@ from registrar.forms.utility.wizard_form_helper import (
from registrar.models import Contact, DomainRequest, DraftDomain, Domain, FederalAgency
from registrar.templatetags.url_helpers import public_site_url
from registrar.utility.enums import ValidationReturnType
from registrar.forms import ContactForm
logger = logging.getLogger(__name__)
@ -386,7 +385,7 @@ class PurposeForm(RegistrarForm):
)
class YourContactForm(RegistrarForm, ContactForm):
class YourContactForm(RegistrarForm):
JOIN = "submitter"
def to_database(self, obj):
@ -409,6 +408,40 @@ class YourContactForm(RegistrarForm, ContactForm):
contact = getattr(obj, "submitter", None)
return super().from_database(contact)
first_name = forms.CharField(
label="First name / given name",
error_messages={"required": "Enter your first name / given name."},
)
middle_name = forms.CharField(
required=False,
label="Middle name (optional)",
)
last_name = forms.CharField(
label="Last name / family name",
error_messages={"required": "Enter your last name / family name."},
)
title = forms.CharField(
label="Title or role in your organization",
error_messages={
"required": ("Enter your title or role in your organization (e.g., Chief Information Officer).")
},
)
email = forms.EmailField(
label="Email",
max_length=None,
error_messages={"invalid": ("Enter your email address in the required format, like name@example.com.")},
validators=[
MaxLengthValidator(
320,
message="Response must be less than 320 characters.",
)
],
)
phone = PhoneNumberField(
label="Phone",
error_messages={"invalid": "Enter a valid 10-digit phone number.", "required": "Enter your phone number."},
)
class OtherContactsYesNoForm(BaseYesNoForm):
"""The yes/no field for the OtherContacts form."""

View file

@ -23,9 +23,6 @@ class RegistrarForm(forms.Form):
# save a reference to a domain request object
if "domain_request" in kwargs:
self.domain_request = kwargs.pop("domain_request", None)
if "contact" in kwargs:
self.contact = kwargs.pop("contact", None)
super(RegistrarForm, self).__init__(*args, **kwargs)

View file

@ -41,20 +41,22 @@
<legend class="usa-sr-only">
Your contact information
</legend>
{% input_with_errors forms.0.first_name %}
{{form.first_name}}
{% comment %}
{% input_with_errors form.first_name %}
{% input_with_errors forms.0.middle_name %}
{% input_with_errors form.middle_name %}
{% input_with_errors forms.0.last_name %}
{% input_with_errors form.last_name %}
{% input_with_errors forms.0.title %}
{% input_with_errors form.title %}
{% input_with_errors forms.0.email %}
{% input_with_errors form.email %}
{% with add_class="usa-input--medium" %}
{% input_with_errors forms.0.phone %}
{% input_with_errors form.phone %}
{% endwith %}
{% endcomment %}
</fieldset>
<div>

View file

@ -75,6 +75,12 @@ class ContactProfileSetupView(ContactPermissionView):
template_name = "finish_contact_setup.html"
form_class = ContactForm
def get_form_kwargs(self, *args, **kwargs):
"""Add domain_info.organization_name instance to make a bound form."""
form_kwargs = super().get_form_kwargs(*args, **kwargs)
form_kwargs["instance"] = self.object
return form_kwargs
def get(self, request, *args, **kwargs):
self._get_contact(request)
context = self.get_context_data(object=self.object)