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

passing attributes to the callback #14

Closed
codivist opened this issue Aug 17, 2015 · 1 comment
Closed

passing attributes to the callback #14

codivist opened this issue Aug 17, 2015 · 1 comment

Comments

@codivist
Copy link

I have list of items on my page, and each item has a form with a delete button. I know which delete button they are pressing by referencing the ID of the item, and so the correct form will get submitted.

<form method="POST" action="/invite/remove" class="form-inline" id="removeInvite_1">
<button type="submit" class="btn btn-danger" id="removeInviteButton_1" data-manager-name="Marty McFly">
    <i class="fa fa-remove"></i>
</button>
</form

When I try to use the following: confirmCallback: removeInvite(id) in the confirmModal, it submits the form right away. The modal still comes up fine, but the form gets submitted before I hit yes or cancel.

Is there a way to pass a value or attribute to the callback?

Here is my js

$(document).on('click', '[id^="removeInviteButton_"]', function(e) {
        e.preventDefault();
        var id = $(this).attr('id').replace('removeInviteButton_', '');
        var name = $(this).data('manager-name');
        $(e.target).confirmModal({
            confirmMessage: 'Are you sure you want to remove ' + name + '?',
            confirmStyle:   'danger',
            confirmAutoOpen: true,
            confirmCallback: removeInvite(id)
        });
    });
@codivist
Copy link
Author

Not sure if this is correct or optimal, but I was able to pass the ID to the callback this way:

$(e.target).confirmModal({
    confirmMessage: 'Are you sure you want to remove ' + name + '?',
    confirmStyle:   'danger',
    confirmAutoOpen: true,
    confirmCallback: removeInvite, id
});

then in my callback function I have:

function removeInvite() {
     $('#removeInvite_' + this.id).submit();
}

In this way, multiple items can be passed to the call back if needed.

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

2 participants