Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails UJS confirm box cancel button callback

I am using Rails jquery ujs for handling ajax within my app. Also I am using a the confirm option for destroying any records. As my current setup, I have hooked up a loading overlay screen on click of data-remote=true link.

All I wanted to know is: Is there a way I can hook a callback event when a user clicks cancel on the confirm box and I can close the loader overlay.

like image 654
swaroopsm Avatar asked Oct 22 '13 11:10

swaroopsm


1 Answers

Yes, you can. Pass in the response object. In CoffeeScript.

  $('selector').on 'confirm:complete', (e, response) ->
    if response
      # User confirmed
    else
      # User cancelled.

In Javascript:

  $('selector').on('confirm:complete', function(e, response) {
    if(response) {
      // User confirmed
    }
    else {
      // User cancelled.
    }
  });
like image 198
Mohamad Avatar answered Sep 23 '22 06:09

Mohamad