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

jQuery-ujs support #86

Closed
JamesPoel opened this issue Jul 10, 2018 · 8 comments
Closed

jQuery-ujs support #86

JamesPoel opened this issue Jul 10, 2018 · 8 comments

Comments

@JamesPoel
Copy link

JamesPoel commented Jul 10, 2018

Can this be updated to support jQuery-ujs. The click handler for that is click.rails but this only triggers click - as such, the actions are being submitted through GET instead of DELETE.

@JamesPoel
Copy link
Author

JamesPoel commented Jul 10, 2018

#For anyone experiencing a similar issue, a workaround is:

$( document ).on( 'click', '[data-apply=confirmation]', function ( e ) {
    var id = $( this ).closest( '.popover.confirmation' ).attr( 'id' );
    $( '[aria-describedby=' + id + ']' ).trigger( 'click.rails' );
    e.preventDefault();
} );

@mistic100
Copy link
Owner

Please provide an example of your usage.

Because the confirmation doesn't do anything on itself, it just blocks the click event and triggers a new click event when the Ok button clicked.

@JamesPoel
Copy link
Author

JamesPoel commented Jul 10, 2018

I am using jquery-ujs as my delete button, which is like this:
<a data-method="delete" href="...">Delete</a>
When clicked, rails submits the action as a delete request - all OK.
With the confirmation plugin enabled, it submits the request as GET request.
I'm not 100% on how ujs works, but it appears that the jquery-ujs onclick event is click.rails and not simply click.
Perhaps it would be possible to check if the click.rails event exists, and if so, trigger it, if not, fallback to click event?

@JamesPoel JamesPoel changed the title DELETE method. jQuery-ujs support Jul 10, 2018
@mistic100
Copy link
Owner

This is ultra specific, I think your solution is the best.

@mistic100
Copy link
Owner

Or I can add a "confirmationEvent" option, by default it will be "click" (or the value of "trigger" for BT4) and is customisable.

@JamesPoel
Copy link
Author

JamesPoel commented Jul 11, 2018

That works for me :)

@mistic100
Copy link
Owner

Available in 2.4.2 and 4.0.1

@juanmoyano
Copy link

juanmoyano commented Nov 15, 2018

It seems that this change breaks functionality with bootstrap v3.3.7 and jQuery v3.3.1.
If I don't explicitly add confirmationEvent: 'click', it doesn't trigger the click event.
The markup for the element is:
<button type="button" class="btn btn-xs btn-default" data-toggle="confirmation"></button>
Library initialization is as follows:
$('body').confirmation({ selector: '[data-toggle=confirmation]', rootSelector: 'body', [...]

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

3 participants