Fix campaign group removal (fixes #249)

Every time a group was added, the event handler for removing group was
set for all rows in group table. This change ensures the event handler
is only set for the newly added group.
pull/291/head
Rob Cutmore 2016-06-09 07:59:54 -04:00
parent c5d6792bba
commit 9ec4dbe917
1 changed files with 10 additions and 5 deletions

View File

@ -302,18 +302,23 @@ $(document).ready(function() {
errorFlash("Error fetching campaigns")
})
$("#groupForm").submit(function() {
groupTable.row.add([
// Add row to group table.
var newRow = groupTable.row.add([
$("#groupSelect").val(),
'<span style="cursor:pointer;"><i class="fa fa-trash-o"></i></span>'
]).draw()
$("#groupTable").on("click", "span>i.fa-trash-o", function() {
]).draw().node();
// Set event handler for removing row from group table.
$(newRow).on("click", "span>i.fa-trash-o", function() {
groupTable.row($(this).parents('tr'))
.remove()
.draw();
})
});
// Clear user input.
$("#groupSelect").val("");
return false;
})
});
// Create the group typeahead objects
groupTable = $("#groupTable").DataTable({
columnDefs: [{