insertDeleteLink = function(row) {
var delCssSelector = $.trim(options.deleteCssClass).replace(/\s+/g, '.'),
addCssSelector = $.trim(options.addCssClass).replace(/\s+/g, '.');
if (row.is('TR')) {
// If the forms are laid out in table rows, insert
// the remove button into the last table cell:
row.children(':last').append('' + '' + '');
}
else if (row.is('UL') || row.is('OL')) {
// If they're laid out as an ordered/unordered list,
// insert an
');
} else {
// Otherwise, just insert the remove button as the
// last child element of the form's container:
row.append('' + '' +'');
}
// Check if we're under the minimum number of forms - not to display delete link at rendering
if (!showDeleteLinks()){
row.find('a.' + delCssSelector).hide();
}
row.find('a.' + delCssSelector).click(function() {
var row = $(this).parents('.' + options.formCssClass),
del = row.find('input:hidden[id $= "-DELETE"]'),
buttonRow = row.siblings("a." + addCssSelector + ', .' + options.formCssClass + '-add'),
forms;
if (del.length) {
// We're dealing with an inline formset.
// Rather than remove this form from the DOM, we'll mark it as deleted
// and hide it, then let Django handle the deleting:
del.val('on');
row.hide();
forms = $('.' + options.formCssClass).not(':hidden');
} else {
row.remove();
// Update the TOTAL_FORMS count:
forms = $('.' + options.formCssClass).not('.formset-custom-template');
totalForms.val(forms.length);
}
for (var i=0, formCount=forms.length; i<formCount; i++) {
// Apply extraClasses to form rows so they're nicely alternating:
applyExtraClasses(forms.eq(i), i);
if (!del.length) {
// Also update names and IDs for all child controls (if this isn't
// a delete-able inline formset) so they remain in sequence:
forms.eq(i).find(childElementSelector).each(function() {
updateElementIndex($(this), options.prefix, i);
});
}
}
// Check if we've reached the minimum number of forms - hide all delete link(s)
if (!showDeleteLinks()){
$('a.' + delCssSelector).each(function(){$(this).hide();});
}
// Check if we need to show the add button:
if (buttonRow.is(':hidden') && showAddButton()) buttonRow.show();
// If a post-delete callback was provided, call it with the deleted form:
if (options.removed) options.removed(row);
return false;
});
};
insertDeleteLink = function(row) { var delCssSelector = $.trim(options.deleteCssClass).replace(/\s+/g, '.'), addCssSelector = $.trim(options.addCssClass).replace(/\s+/g, '.'); if (row.is('TR')) { // If the forms are laid out in table rows, insert // the remove button into the last table cell: row.children(':last').append('' + '' + ''); } else if (row.is('UL') || row.is('OL')) { // If they're laid out as an ordered/unordered list, // insert an
// Check if we're under the minimum number of forms - not to display delete link at rendering if (!showDeleteLinks()){ row.find('a.' + delCssSelector).hide(); } row.find('a.' + delCssSelector).click(function() { var row = $(this).parents('.' + options.formCssClass), del = row.find('input:hidden[id $= "-DELETE"]'), buttonRow = row.siblings("a." + addCssSelector + ', .' + options.formCssClass + '-add'), forms; if (del.length) { // We're dealing with an inline formset. // Rather than remove this form from the DOM, we'll mark it as deleted // and hide it, then let Django handle the deleting:
del.val('on'); row.hide(); forms = $('.' + options.formCssClass).not(':hidden'); } else { row.remove();
// Update the TOTAL_FORMS count: forms = $('.' + options.formCssClass).not('.formset-custom-template'); totalForms.val(forms.length); } for (var i=0, formCount=forms.length; i<formCount; i++) { // Apply
extraClasses
to form rows so they're nicely alternating: applyExtraClasses(forms.eq(i), i); if (!del.length) { // Also update names and IDs for all child controls (if this isn't // a delete-able inline formset) so they remain in sequence: forms.eq(i).find(childElementSelector).each(function() { updateElementIndex($(this), options.prefix, i); }); } } // Check if we've reached the minimum number of forms - hide all delete link(s) if (!showDeleteLinks()){ $('a.' + delCssSelector).each(function(){$(this).hide();}); } // Check if we need to show the add button: if (buttonRow.is(':hidden') && showAddButton()) buttonRow.show(); // If a post-delete callback was provided, call it with the deleted form: if (options.removed) options.removed(row); return false; }); };