Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete confirmation triggered twice in an inner repeater #42

Open
tommica opened this issue Jan 7, 2017 · 7 comments
Open

Delete confirmation triggered twice in an inner repeater #42

tommica opened this issue Jan 7, 2017 · 7 comments

Comments

@tommica
Copy link

tommica commented Jan 7, 2017

My JS looks like this:

    $('.out_repeater').repeater({
        show: function () {
            $(this).slideDown();
        },
        hide: function (deleteElement) {
            if (confirm('Are you sure you want to delete this element?')) {
                $(this).slideUp(deleteElement);
            }
        },
        isFirstItemUndeletable: true,
        repeaters: [{
            selector: '.in_repeater',
            show: function () {
                $(this).slideDown();
            },
            hide: function (deleteElement) {
                if (confirm('Are you sure you want to delete this element?')) {
                    $(this).slideUp(deleteElement);
                }
            }
        }]
    });

For some reason when the delete button for an item inside the "in_repeater", it triggers the "Are you sure" confirmation twice.

Everything else works fine!

<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery.repeater/1.2.1/jquery.repeater.min.js"></script>
@dragosstancu
Copy link

dragosstancu commented Aug 9, 2017

The click event is being captured at list level and, for nested repeaters, it happens as many times as deep the nesting is.

Replace that in jquery.repeater.js, towards the end.

$list.on('click', '[data-repeater-delete]', function(event) {
event.stopPropagation(); // added this
var self = $(this).closest('[data-repeater-item]').get(0);
hide.call(self, function() {
$(self).remove();
setIndexes($items(), getGroupName(), fig.repeaters);
});
});

@havanan
Copy link

havanan commented Nov 28, 2017

I also have a similar problem, but when I change the code of the dragosstancu, still repeated the warning: "Are you sure"

@martinmurciego
Copy link

martinmurciego commented Nov 22, 2018

Please, give a more detailed example in jsfiddle or codepen about eliminating nested repeaters, since I have this same problem. As I must respond with a different behavior to the slideUp and slideDown of each repeater I need to be able to identify each one: #98 (comment)
Some alternative or it will be that the developer can update this suggested change in a new version.

$list.on('click', '[data-repeater-delete]', function(event) {
event.stopPropagation(); // added this
var self = $(this).closest('[data-repeater-item]').get(0);
hide.call(self, function() {
$(self).remove();
setIndexes($items(), getGroupName(), fig.repeaters);
});
});

@dragosstancu
Copy link

Hi guys,
All I can do for now is to post a link to my page that demonstrates the nested repeaters: https://demo.webfixtech.com/repeater/

@martinmurciego
Copy link

Cool. Thank you for sharing this.

@ilic993
Copy link

ilic993 commented Jul 27, 2019

@dragosstancu Thank you for the fix, I hope this gets included in the next release.

@AbhishekGandhi7
Copy link

$list.on('click', '[data-repeater-delete]', function(event) {
event.stopImmediatePropagation(); // add this, It works for me perfectly
// event.stopPropagation();
var self = $(this).closest('[data-repeater-item]').get(0);
hide.call(self, function() {
$(self).remove();
setIndexes($items(), getGroupName(), fig.repeaters);
});
});

Thanks @martinmurciego it's save my day.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants