rails/jquery-ujs — Issue #235: Make $.rails.confirm() function event-based
Author: symve
Created: 2012-01-05 20:16:57+00:00
State: open

This is an enhancement request for the confirm dialog override logic:

// Default confirm dialog, may be overridden with custom confirm dialog in $.rails.confirm
confirm: function(message) {
return confirm(message);
},

The current implementation requires the use of the browser's native confirm dialog box, as the user's response value must be returned at the end of the $.rails.confirm function.

Native browser dialogs are not that nice (they are modal and cannot be styled) so often a custom dialog or overlay is used. In that case, the user's response comes in asynchronously and the overridden $.rails.confirm function can no longer return the user's response value immediately.

If the responsibility of firing the response event is added to the "confirm function override" contract, this would be possible.
In other words, this issue is a request to move to a more event-based confirmation logic, making the base implementation something like:

// Default confirm dialog, may be overridden with custom confirm dialog in $.rails.confirm
// Make sure to fire the confirm:complete event once the user's response is known
confirm: function(message) {
var answer = confirm(message);
rails.fire(element, 'confirm:complete', [answer]);
},

Now complete freedom is given as long as once the user has made a choice, the confirm:complete event is fired.

Unfortunately it looks like the allowAction() usage logic will also need to become event based, making this a non-trivial change, but I hope you'll find this a worthwhile enhancement to make.