diff --git a/html/forms/attach-alert-template.inc.php b/html/forms/attach-alert-template.inc.php
index efa97f01e..9303b4eaa 100644
--- a/html/forms/attach-alert-template.inc.php
+++ b/html/forms/attach-alert-template.inc.php
@@ -36,7 +36,7 @@ else {
}
if ($success === true) {
- dbDelete('alert_template_map', 'id NOT IN ('.implode(',', $ids).')');
+ dbDelete('alert_template_map', 'id NOT IN ('.implode(',', $ids).') AND alert_templates_id =?',array($_POST['template_id']));
echo "Alert rules have been attached to this template. $template_map_ids";
exit;
}
diff --git a/html/includes/modal/attach_alert_template.inc.php b/html/includes/modal/attach_alert_template.inc.php
index 5aa0e8c48..3e16014cc 100644
--- a/html/includes/modal/attach_alert_template.inc.php
+++ b/html/includes/modal/attach_alert_template.inc.php
@@ -64,14 +64,20 @@ $('#attach-alert-template').on('show.bs.modal', function(e) {
data: { type: "parse-template-rules", template_id: template_id },
dataType: "json",
success: function(output) {
- arr = [];
+ selected_items = [];
$.each( output.rule_id, function( i, elem) {
- $('#rules_list option[value='+elem+']').attr("selected", true);
+ elem = parseInt(elem);
+ selected_items.push(elem);
});
+ $('#rules_list').val(selected_items);
}
});
});
+$('#attach-alert-template').on('hide.bs.modal', function(e) {
+ $('#rules_list').val([]);
+});
+
$('#alert-template-attach').click('', function(event) {
event.preventDefault();
var template_id = $("#template_id").val();