Skip to content
This repository has been archived by the owner on Jan 30, 2019. It is now read-only.

Commit

Permalink
Passed soon-to-be removed element to beforeDelete callback
Browse files Browse the repository at this point in the history
  • Loading branch information
jenwachter committed Dec 14, 2017
1 parent e30b7c5 commit f01c075
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ When a user clicks on the `.add` button, the script will render a new `.field-gr
* __max__: _Optional_. (integer) The maximum number of field group elements that may be added to the repeatable item container. Default: null.
* __min__: _Optional_. (integer) The minimum number of field group elements that may be present in the repeatable item container. The form is prepopulated with this amount of field group elements. Default: 0.
* __beforeAdd__: _Optional_. (function) A function to run before an item is added to the repeatable item container. Default: none
* __beforeDelete__: _Optional_. (function) A function to run before an item is deleted from the repeatable item container. Default: none
* __afterAdd__: _Optional_. (function (addedItem)) A function to run after an item is added to the repeatable item container. Default: none
* __beforeDelete__: _Optional_. (function (itemToDelete)) A function to run before an item is deleted from the repeatable item container. Default: none
* __afterDelete__: _Optional_. (function) A function to run after an item is deleted from the repeatable item container. Default: none
* __template__: _Required_. (string) The selector that contains the form field group template.
9 changes: 5 additions & 4 deletions jquery.repeatable.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
template: null,
itemContainer: ".field-group",
beforeAdd: function () {},
beforeDelete: function () {},
afterAdd: function (item) {},
beforeDelete: function (item) {},
afterDelete: function () {}
};

Expand Down Expand Up @@ -71,9 +71,10 @@
*/
var deleteOne = function (e) {
e.preventDefault();
settings.beforeDelete.call(this);
if (total === settings.min) return;
$(this).parents(settings.itemContainer).first().remove();
if (total === settings.min) return;
var item = $(this).parents(settings.itemContainer).first();
settings.beforeDelete.call(this, item);
item.remove();
total--;
maintainAddBtn();
settings.afterDelete.call(this);
Expand Down

0 comments on commit f01c075

Please sign in to comment.