diff --git a/nested_inline/static/admin/js/inlines-nested.js b/nested_inline/static/admin/js/inlines-nested.js index 6f62766..c5d0cd9 100644 --- a/nested_inline/static/admin/js/inlines-nested.js +++ b/nested_inline/static/admin/js/inlines-nested.js @@ -97,6 +97,13 @@ } row.remove(); change_no_forms(options.prefix, false); + // check if add row is to be shown + if ((get_max_forms(options.prefix) !== '') && (get_max_forms(options.prefix) - get_no_forms(options.prefix)) > 0) { + var add_row = formset_to_update.find('div.add-row:contains(\''+ options.addText + '\')') + if (add_row && !add_row.is(':visible')) { + add_row.show() + } + } // If a post-delete callback was provided, call it with the deleted form: if (options.removed) { options.removed(formset_to_update); @@ -305,17 +312,24 @@ template.find(".nested-inline-row").remove(); // Make a new form template_form = template.find("#" + normalized_formset_prefix + "-empty") - new_form = template_form.clone().removeClass(options.emptyCssClass).addClass("dynamic-" + formset_prefix); - - new_form.insertBefore(template_form); - - var inputs = new_form.find('input'); + var inputs = template_form.find('input'); inputs.each(function () { var $input = $(this) - if ($input.val()) { + if ($input.attr('type') == 'hidden' && $input.val()) { $input.removeAttr('value') } }); + new_form = template_form.clone().removeClass(options.emptyCssClass).addClass("dynamic-" + formset_prefix); + + new_form.insertBefore(template_form); + + // var inputs = new_form.find('input'); + // inputs.each(function () { + // var $input = $(this) + // if ($input.val()) { + // $input.removeAttr('value') + // } + // }); // Update Form Properties update_props(template, normalized_formset_prefix, formset_prefix); @@ -352,17 +366,24 @@ template.find(".inline-related").not(".empty-form").remove(); // Make a new form template_form = template.find("#" + normalized_formset_prefix + "-empty") - new_form = template_form.clone().removeClass(options.emptyCssClass).addClass("dynamic-" + formset_prefix); - - new_form.insertBefore(template_form); - - var inputs = new_form.find('input'); + var inputs = template_form.find('input'); inputs.each(function () { var $input = $(this) - if ($input.val()) { + if ($input.attr('type') == 'hidden' && $input.val()) { $input.removeAttr('value') } }); + new_form = template_form.clone().removeClass(options.emptyCssClass).addClass("dynamic-" + formset_prefix); + + new_form.insertBefore(template_form); + + // var inputs = new_form.find('input'); + // inputs.each(function () { + // var $input = $(this) + // if ($input.val()) { + // $input.removeAttr('value') + // } + // }); // Update Form Properties new_form.find('.inline_label').text('#1');