There is a code to add the formset for the site. You need to add a delete button for each new formset. respectively from the buttons will be the same id, and has and formseta. Please tell me how to make buttons with different id?
$('#add_issueforinvoice').on('click', function(e) {
e.preventDefault();
var form_count = $('#id_invoiceforproject_set-TOTAL_FORMS').val(),
id = '#invoice_' + (parseInt(form_count)),
prev = parseInt(form_count),
count = parseInt(form_count) + 1,
form_group = $('#invoice_1');
var new_form_group = form_group.clone().prop(
'id', 'invoice_' + count
).insertAfter($(id));
$('#invoice_' + count).find('div').prop('id', function(index, id) {
if (this.id)
return this.id.replace('set-0-', 'set-' + (count - 1) + '-');
});
$('#invoice_' + count).find('select').prop('id', function(index, id) {
if (this.id)
return this.id.replace('set-0-', 'set-' + (count - 1) + '-');
});
$('#invoice_' + count).find('select').prop('name', function(index, id) {
if (this.name)
return this.name.replace('set-0-', 'set-' + (count - 1) + '-');
});
$('#invoice_' + count).find('label').attr('for', function(index, id) {
if (this.for)
return this.id.replace('set-0-', 'set-' + (count - 1) + '-');
});
$('#invoice_' + count).find('input').prop('name', function(index, id) {
if (this.name)
return this.name.replace('set-0-', 'set-' + (count - 1) + '-');
});
$('#invoice_' + count).find('input').prop('id', function(index, id) {
if (this.id)
return this.id.replace('set-0-', 'set-' + (count - 1) + '-');
});
$('#id_invoiceforproject_set-TOTAL_FORMS').val(parseInt(form_count) + 1);
<script src="http://ift.tt/ILQp6H"></script>
Aucun commentaire:
Enregistrer un commentaire