diff --git a/src/registrar/forms/application_wizard.py b/src/registrar/forms/application_wizard.py index ae7590c53..1e067ba8a 100644 --- a/src/registrar/forms/application_wizard.py +++ b/src/registrar/forms/application_wizard.py @@ -141,6 +141,7 @@ class RegistrarFormSet(forms.BaseFormSet): """ if not self.is_valid(): return + logger.info(obj) obj.save() query = getattr(obj, join).order_by("created_at").all() # order matters @@ -162,6 +163,8 @@ class RegistrarFormSet(forms.BaseFormSet): for db_obj, post_data in zip_longest(query, self.forms, fillvalue=None): cleaned = post_data.cleaned_data if post_data is not None else {} + logger.info(post_data) + logger.info(cleaned) # matching database object exists, update it if db_obj is not None and cleaned: if should_delete(cleaned): @@ -708,6 +711,7 @@ class BaseOtherContactsFormSet(RegistrarFormSet): return all(empty) or self.formset_data_marked_for_deletion def to_database(self, obj: DomainApplication): + logger.info("in to_database for BaseOtherContactsFormSet") self._to_database(obj, self.JOIN, self.REVERSE_JOINS, self.should_delete, self.pre_update, self.pre_create) @classmethod @@ -737,6 +741,7 @@ OtherContactsFormSet = forms.formset_factory( extra=0, absolute_max=1500, # django default; use `max_num` to limit entries min_num=1, + can_delete=True, validate_min=True, formset=BaseOtherContactsFormSet, ) diff --git a/src/registrar/templates/application_other_contacts.html b/src/registrar/templates/application_other_contacts.html index e71039e69..3d3977d47 100644 --- a/src/registrar/templates/application_other_contacts.html +++ b/src/registrar/templates/application_other_contacts.html @@ -39,6 +39,10 @@

Organization contact {{ forloop.counter }} (optional)

+ {% if forms.1.can_delete %} + {{ form.DELETE }} + {% endif %} + {% input_with_errors form.first_name %} {% input_with_errors form.middle_name %} diff --git a/src/registrar/views/application.py b/src/registrar/views/application.py index e431f4b0a..1525021e4 100644 --- a/src/registrar/views/application.py +++ b/src/registrar/views/application.py @@ -277,6 +277,7 @@ class ApplicationWizard(ApplicationWizardPermissionView, TemplateView): for form in forms: data = form.from_database(self.application) if self.has_pk() else None if use_post: + logger.info("about to instantiate form ") instantiated.append(form(self.request.POST, **kwargs)) elif use_db: instantiated.append(form(data, **kwargs)) @@ -389,6 +390,7 @@ class ApplicationWizard(ApplicationWizardPermissionView, TemplateView): return self.goto(self.steps.first) forms = self.get_forms(use_post=True) + logger.info("after geting forms") if self.is_valid(forms): # always save progress self.save(forms) @@ -506,10 +508,14 @@ class OtherContacts(ApplicationWizard): if other_contacts_yes_no_form.is_valid(): # test for has_contacts if other_contacts_yes_no_form.cleaned_data.get("has_other_contacts"): + logger.info("has other contacts") # mark the no_other_contacts_form for deletion no_other_contacts_form.mark_form_for_deletion() + logger.info("after marking 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:]) + logger.info("after checking forms for validity") + logger.info(f"all forms valid = {all_forms_valid}") else: # mark the other_contacts_forms formset for deletion other_contacts_forms.mark_formset_for_deletion()