Skip to content

Commit

Permalink
Pass the current row for removal when calling beforeDeleteRow event
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugene Tupikov committed Oct 2, 2015
1 parent 09f3762 commit e9a122c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Yii2 multiple input change log
--------------------

- Bug #39: TabularInput: now new row does't copy values from the most recent row
- Enh #40: Pass the current row for removal when calling `beforeDeleteRow` event


1.2.3
-----
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,10 @@ jQuery('#multiple-input').on('afterInit', function(){
console.log('calls on before add row event');
}).on('afterAddRow', function(e) {
console.log('calls on after add row event');
}).on('beforeDeleteRow', function(){
console.log('calls on before remove row event');
}).on('beforeDeleteRow', function(e, row){
// row - HTML container of the current row for removal.
// For TableRenderer it is tr.multiple-input-list__item
console.log('calls on before remove row event.');
return confirm('Are you sure you want to delete row?')
}).on('afterDeleteRow', function(){
console.log('calls on after remove row event');
Expand Down
12 changes: 6 additions & 6 deletions src/assets/src/js/jquery.multipleInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
/**
* beforeDeleteRow event is triggered before row will be removed.
* The signature of the event handler should be:
* function (event)
* where event is an Event object.
* function (event, row)
* where event is an Event object and row is html container of row for removal
*
* If the handler returns a boolean false, it will stop removal the row.
*/
Expand Down Expand Up @@ -157,18 +157,18 @@

removeInput: function () {
var $wrapper = $(this).closest('.multiple-input').first(),
line = $(this).closest('.multiple-input-list__item');
$toDelete = $(this).closest('.multiple-input-list__item');

var event = $.Event(events.beforeDeleteRow);
$wrapper.trigger(event);
$wrapper.trigger(event, [$toDelete]);
if (event.result === false) {
return;
}

line.find('input, select, textarea').each(function () {
$toDelete.find('input, select, textarea').each(function () {
methods.removeAttribute.apply(this);
});
line.fadeOut(300, function () {
$toDelete.fadeOut(300, function () {
$(this).remove();
});

Expand Down
2 changes: 1 addition & 1 deletion src/assets/src/js/jquery.multipleInput.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e9a122c

Please sign in to comment.