Skip to content

Commit

Permalink
Added functionality to set dirty form flag on 'Add' and 'Remove' button.
Browse files Browse the repository at this point in the history
  • Loading branch information
juhijariwala committed Jun 16, 2015
1 parent daf684e commit 9d764cb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ var EnvironmentVariableEdit = function (options) {
})
};

var EnvironmentVariableAddRemove = function(parentElement) {
var EnvironmentVariableAddRemove = function(parentElement, options) {
var $ = jQuery;

var addButton = $(parentElement).find('.add_item');
Expand All @@ -93,12 +93,19 @@ var EnvironmentVariableAddRemove = function(parentElement) {
addButton.on('click.environmentVariableTemplateCopy', function(evt){
evt.preventDefault();
addRowTo.append(template);
if(options.onAdd){
options.onAdd(addButton);
}
});

$(parentElement).on('click.environmentVariableTemplateCopy', '.delete_parent', function(evt){
evt.preventDefault();
var deleteLink = $(evt.target);
deleteLink.parents('.environment-variable-edit-row').remove();
if(options.onRemove){
options.onRemove(deleteLink);
}

});

};
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,14 @@
(function ($) {
$(function () {
EnvironmentVariableEdit({tableRowSelector: '.environment-variable-edit-row'});
EnvironmentVariableAddRemove($('#<%=template_row_id_prefix-%>'));
EnvironmentVariableAddRemove($('#<%=template_row_id_prefix-%>'), {
onAdd: function(addButton){
addButton.parents('form.dirtyform').data('dirty', true);
},
onRemove: function(deleteLink){
deleteLink.parents('form.dirtyform').data('dirty', true);
}
});
});
})(jQuery);
</script>

0 comments on commit 9d764cb

Please sign in to comment.