question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Asynchronous $.rails.confirm

See original GitHub issue

These function:

confirm: function(message) {
  return confirm(message);
}

Do not allow us to use a custom confirmation because return the confirmation immediately.

I would to use something like jQuery UI Dialog, take a look: http://jqueryui.com/demos/dialog/#modal-confirmation

This requires a major change on this function to something like that:

confirm: function(message, success) {
  $( "#dialog-confirm" ).dialog({
    resizable: false,
    height:140,
    modal: true,
    buttons: {
      "Yes": function() {
        $( this ).dialog( "close" );

        // execute the function that means "I confirm"
        success();
      },
      "No": function() {
        $( this ).dialog( "close" );
      }
    }
  });
}

This approach will allow us to customize the entire confirmation because window.confirm() is not equal between all browsers.

To keep the current confirmation working will be something like that:

confirm: function(message, success) {
  if (confirm(message)) {
    success();
  }
}

The success function should redirect to link or submit the form or what should be necessary.

Our users frequently calls support telling things like: “I clicked on Cancel Item link and appeared ok and cancel. I don’t want to cancel the item anymore, what should I do? ok means what? cancel means what?”

Think about it:

Are you sure you want to cancel the item?

[ ok ] [ cancel ]

It is not clear enough than:

Are you sure you want to cancel the item?

[ yes ] [ no ]

If you want to be more user friendly:

Are you sure you want to cancel the item?

[ Yes, I want to cancel the item ] [ Do not cancel and list the items again ]

What you think?

I guess we can keep backwards compatibility simply checking the $.rails.confirm signature.

Issue Analytics

  • State:closed
  • Created 11 years ago
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
travishaynescommented, Sep 24, 2016

Here’s my solution. It doesn’t rely on “undocumented browser/javascript/jquery features,” like the asynchronous-call-to-confirm branch does. All it does is store the answer in a data attribute and fire the event again when it’s true.

$.rails.allowAction = function(element) {
  var message = element.data('confirm');

  if (!message) { return true; }

  if (element.data('confirmed')) {
    element.data('confirmed', false);

    return $.rails.fire(element, 'confirm:complete', [true]);
  }

  if ($.rails.fire(element, 'confirm')) {
    try {
      openYourAsyncConfirmDialogHere(message, function(answer){
        element.data('confirmed', answer);
        callback = $.rails.fire(element, 'confirm:complete', [answer]);
        if(answer && callback) { $.rails.fire(element, 'click'); }
      });
    } catch (e) {
      (console.error || console.log).call(console, e.stack || e);
    }
  }

  return false;
}
0reactions
shlimacommented, Nov 10, 2015

+1

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to test Ruby on Rails methods that involve asynchronous ...
I have a method that creates a record and waits for it to receive input in a loop that occurs until the record's...
Read more >
Asynchronous HTTP requests in Rails - Remi Mercier
The first thing I like to do, is to check the HTTP status sent from my controller. If it's a 200 , I'll...
Read more >
Sending async data from Rails into the world | Arkency Blog
Async. The Rails app can use async interface to ZMQ and never block for sending message. However it means that some messages might...
Read more >
Active Job Basics - Ruby on Rails Guides
Rails by default comes with an asynchronous queuing implementation that runs jobs with an in-process thread pool. Jobs will run asynchronously, but any...
Read more >
Ruby on Rails Gotcha: Asynchronous loading of Javascript in ...
Everyone knows that you shouldn't block page rendering by synchronously loading a big chunk of javascript in the head of your page right?...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found