fix: restore "add another" button on secr rooms and rolodex edit pages (#4467)

* fix: replace inline JS for "Add another" on secr rooms page

* fix: update rolodex edit page to re-enable "Add another" button

* refactor: use new class instead of reusing inline-related

The "inline-related" class has styling rules, etc. To avoid accidental
styling changes, use "dynamic-inline" as a class to indicate which tr
elements should be managed.
This commit is contained in:
Jennifer Richards 2022-09-16 14:35:32 -03:00 committed by GitHub
parent 4a68b92c03
commit 4dd220b980
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 11 deletions

View file

@ -28,13 +28,15 @@ function add_inline_form(name) {
// check to see if this is a stacked or tabular inline
if (first.hasClass("tabular")) {
var field_table = first.parent().find('table > tbody')
var count = field_table.children().length
var copy = $('tr:last', field_table).clone(true)
const children = field_table.children('tr.dynamic-inline')
var count = children.length
const last = $(children[count-1])
var copy = last.clone(true)
copy.removeClass("row1 row2")
copy.find("input[name$='address']").removeAttr("readonly")
copy.addClass("row"+((count % 2) == 0 ? 1 : 2))
field_table.append(copy)
increment_form_ids($('tr:last', field_table), count, name)
copy.find("input[name$='address']").attr("readonly", false)
copy.addClass("row"+((count % 2) ? 2 : 1))
copy.insertAfter(last)
increment_form_ids($(copy), count, name)
}
else {
var last = $(first).parent().children('.last-related')
@ -54,13 +56,14 @@ function add_inline_form(name) {
$(function() {
var html_template = '<ul class="tools">'+
'<li>'+
'<a class="addlink" href="#" onclick="return add_inline_form(\'{{prefix}}\')">'+
'<a id="addlink-{{prefix}}" class="addlink" href="#">'+
'Add another</a>'+
'</li>'+
'</ul>'
$('.inline-group').each(function(i) {
//prefix is in the name of the input fields before the "-"
var prefix = $("input[type='hidden'][name!='csrfmiddlewaretoken']", this).attr("name").split("-")[0]
$(this).append(html_template.replace("{{prefix}}", prefix))
var prefix = $("input[type='hidden'][name!='csrfmiddlewaretoken']", this).attr("name").split("-")[0];
$(this).append(html_template.replace("{{prefix}}", prefix));
$('#addlink-' + prefix).on('click', () => add_inline_form(prefix));
})
})

View file

@ -28,7 +28,7 @@
{% if form.non_field_errors %}
<tr><td colspan="3">{{ form.non_field_errors }}</td></tr>
{% endif %}
<tr class="{% cycle 'row1' 'row2' %}">
<tr class="dynamic-inline {% cycle 'row1' 'row2' %}">
<td>
{% for hidden in form.hidden_fields %}
{{ hidden }}

View file

@ -43,7 +43,7 @@
<tbody>
{% for form in email_formset.forms %}
{% if form.non_field_errors %}{{ form.non_field_errors }}{% endif %}
<tr class="{% cycle 'row1' 'row2' %}">
<tr class="dynamic-inline {% cycle 'row1' 'row2' %}">
<td>
{# Include the hidden fields in the form #}
{% for hidden in form.hidden_fields %}