handling of form when no options selected; initial styling of form elements

This commit is contained in:
David Kennedy 2024-01-04 07:27:05 -05:00
parent 2e737bf4d8
commit b15c21c398
No known key found for this signature in database
GPG key ID: 6528A5386E66B96B
3 changed files with 29 additions and 17 deletions

View file

@ -736,8 +736,9 @@ class NoOtherContactsForm(RegistrarForm):
required=True,
# label has to end in a space to get the label_suffix to show
label=(
"Please explain why there are no other employees from your organization "
"we can contact to help us assess your eligibility for a .gov domain."
"You don't need to provide names of other employees now, but it may "
"slow down our assessment of your eligibility. Describe why there are "
"no other employees who can help verify your request."
),
widget=forms.Textarea(),
validators=[

View file

@ -13,15 +13,25 @@
{% endblock %}
{% block form_required_fields_help_text %}
{% include "includes/required_fields.html" %}
{# commenting out to remove this block from this point in the page #}
{% endblock %}
{% block form_fields %}
{{ forms.0 }}
<fieldset class="usa-fieldset margin-top-2">
<legend>
<h2>Are there other employees who can help verify your request?</h2>
</legend>
{% with add_class="usa-radio__input--tile" add_legend_class="usa-sr-only" %}
{% input_with_errors forms.0.has_other_contacts %}
{% endwith %}
{# forms.0 is a small yes/no form that toggles the visibility of "other contact" formset #}
</fieldset>
<div id="other-employees">
{% include "includes/required_fields.html" %}
{{ forms.1.management_form }}
{# forms.1 is a formset and this iterates over its forms #}
{% for form in forms.1.forms %}
@ -59,6 +69,10 @@
</div>
<div id="no-other-employees">
<fieldset class="usa-fieldset margin-top-2">
<legend>
<h2>No other employees from your organization?</h2>
</legend>
{% with attr_maxlength=1000 %}
{% input_with_errors forms.2.no_other_contacts_rationale %}
{% endwith %}

View file

@ -385,6 +385,7 @@ class ApplicationWizard(ApplicationWizardPermissionView, TemplateView):
# always save progress
self.save(forms)
else:
logger.info("all forms are not valid")
context = self.get_context_data()
context["forms"] = forms
return render(request, self.template_name, context)
@ -501,26 +502,22 @@ class OtherContacts(ApplicationWizard):
# test for has_contacts
if other_contacts_yes_no_form.cleaned_data.get('has_other_contacts'):
logger.info("has other contacts")
# remove data from no_other_contacts_form and set
# form to always_valid
# mark the no_other_contacts_form for deletion
no_other_contacts_form.mark_form_for_deletion()
# test that the other_contacts_forms and no_other_contacts_forms are valid
all_forms_valid = all(form.is_valid() for form in forms[1:])
else:
logger.info("has no other contacts")
# remove data from each other_contacts_form
# mark the other_contacts_forms formset for deletion
other_contacts_forms.mark_formset_for_deletion()
# set the delete data to on in each form
# Create a mutable copy of the QueryDict
# mutable_data = QueryDict(mutable=True)
# mutable_data.update(self.request.POST.copy())
# for i, form in enumerate(other_contacts_forms.forms):
# form_prefix = f'other_contacts-{i}'
# mutable_data[f'{form_prefix}-deleted'] = 'on'
# other_contacts_forms.forms[i].data = mutable_data.copy()
all_forms_valid = all(form.is_valid() for form in forms[1:])
else:
logger.info("yes no form is invalid")
# if yes no form is invalid, no choice has been made
# mark other forms for deletion so that their errors are not
# returned
other_contacts_forms.mark_formset_for_deletion()
no_other_contacts_form.mark_form_for_deletion()
all_forms_valid = False
return all_forms_valid