From 9ec4dbe917a8d443effe629afcf3df7caa8a123f Mon Sep 17 00:00:00 2001 From: Rob Cutmore Date: Thu, 9 Jun 2016 07:59:54 -0400 Subject: [PATCH 1/2] 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. --- static/js/app/campaigns.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/static/js/app/campaigns.js b/static/js/app/campaigns.js index f9bb84b0..d98afd24 100644 --- a/static/js/app/campaigns.js +++ b/static/js/app/campaigns.js @@ -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(), '' - ]).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: [{ From 5ca77442706f68352eb16fa02012c1a8228b4a0e Mon Sep 17 00:00:00 2001 From: Rob Cutmore Date: Thu, 9 Jun 2016 08:14:26 -0400 Subject: [PATCH 2/2] Fix indentation for group form submit --- static/js/app/campaigns.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/static/js/app/campaigns.js b/static/js/app/campaigns.js index d98afd24..f04e88ef 100644 --- a/static/js/app/campaigns.js +++ b/static/js/app/campaigns.js @@ -302,24 +302,24 @@ $(document).ready(function() { errorFlash("Error fetching campaigns") }) $("#groupForm").submit(function() { - // Add row to group table. - var newRow = groupTable.row.add([ - $("#groupSelect").val(), - '' - ]).draw().node(); + // Add row to group table. + var newRow = groupTable.row.add([ + $("#groupSelect").val(), + '' + ]).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; + // 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(); }); - // Create the group typeahead objects + + // Clear user input. + $("#groupSelect").val(""); + return false; + }); + // Create the group typeahead objects groupTable = $("#groupTable").DataTable({ columnDefs: [{ orderable: false,