mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-03 09:43:33 +02:00
remove errors from being returned if forms are deleted, js to hide deleted forms on page load
This commit is contained in:
parent
dcce354224
commit
e90474cab1
2 changed files with 38 additions and 5 deletions
|
@ -463,9 +463,26 @@ function prepareDeleteButtons(formLabel) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* On form load, hide deleted forms, ie. those forms with hidden input of class 'deletion'
|
||||||
|
* with value='on'
|
||||||
|
*/
|
||||||
|
function hideDeletedForms() {
|
||||||
|
let hiddenDeleteButtonsWithValueOn = document.querySelectorAll('input[type="hidden"].deletion[value="on"]');
|
||||||
|
|
||||||
|
// Iterating over the NodeList of hidden inputs
|
||||||
|
hiddenDeleteButtonsWithValueOn.forEach(function(hiddenInput) {
|
||||||
|
// Finding the closest parent element with class "repeatable-form" for each hidden input
|
||||||
|
var repeatableFormToHide = hiddenInput.closest('.repeatable-form');
|
||||||
|
|
||||||
|
// Checking if a matching parent element is found for each hidden input
|
||||||
|
if (repeatableFormToHide) {
|
||||||
|
// Setting the display property to "none" for each matching parent element
|
||||||
|
repeatableFormToHide.style.display = 'none';
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -500,6 +517,9 @@ function prepareDeleteButtons(formLabel) {
|
||||||
addButton.setAttribute("disabled", "true");
|
addButton.setAttribute("disabled", "true");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Hide forms which have previously been deleted
|
||||||
|
hideDeletedForms()
|
||||||
|
|
||||||
// Attach click event listener on the delete buttons of the existing forms
|
// Attach click event listener on the delete buttons of the existing forms
|
||||||
prepareDeleteButtons(formLabel);
|
prepareDeleteButtons(formLabel);
|
||||||
|
|
||||||
|
|
|
@ -780,12 +780,12 @@ class OtherContactsForm(RegistrarForm):
|
||||||
"""
|
"""
|
||||||
This method overrides the default behavior for forms.
|
This method overrides the default behavior for forms.
|
||||||
This cleans the form after field validation has already taken place.
|
This cleans the form after field validation has already taken place.
|
||||||
In this override, allow for a form which is empty to be considered
|
In this override, allow for a form which is empty, or one marked for
|
||||||
valid even though certain required fields have not passed field
|
deletion to be considered valid even though certain required fields have
|
||||||
validation
|
not passed field validation
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if self.form_data_marked_for_deletion:
|
if self.form_data_marked_for_deletion or self.cleaned_data["DELETE"]:
|
||||||
# clear any errors raised by the form fields
|
# clear any errors raised by the form fields
|
||||||
# (before this clean() method is run, each field
|
# (before this clean() method is run, each field
|
||||||
# performs its own clean, which could result in
|
# performs its own clean, which could result in
|
||||||
|
@ -810,6 +810,19 @@ class OtherContactsForm(RegistrarForm):
|
||||||
|
|
||||||
|
|
||||||
class BaseOtherContactsFormSet(RegistrarFormSet):
|
class BaseOtherContactsFormSet(RegistrarFormSet):
|
||||||
|
"""
|
||||||
|
FormSet for Other Contacts
|
||||||
|
|
||||||
|
There are two conditions by which a form in the formset can be marked for deletion.
|
||||||
|
One is if the user clicks 'DELETE' button, and this is submitted in the form. The
|
||||||
|
other is if the YesNo form, which is submitted with this formset, is set to No; in
|
||||||
|
this case, all forms in formset are marked for deletion. Both of these conditions
|
||||||
|
must co-exist.
|
||||||
|
Also, other_contacts have db relationships to multiple db objects. When attempting
|
||||||
|
to delete an other_contact from an application, those db relationships must be
|
||||||
|
tested and handled; this is configured with REVERSE_JOINS, which is an array of
|
||||||
|
strings representing the relationships between contact model and other models.
|
||||||
|
"""
|
||||||
JOIN = "other_contacts"
|
JOIN = "other_contacts"
|
||||||
REVERSE_JOINS = [
|
REVERSE_JOINS = [
|
||||||
"user",
|
"user",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue