Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show the Add Row button when max rows is achieved and then a row is d… #81

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 33 additions & 12 deletions nested_inline/static/admin/js/inlines-nested.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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');
Expand Down