Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add support for confirmation for button. closes issue #14

  • Loading branch information...
commit 632150182d931bdc69731986016ba41f494e796c 1 parent 8f2780b
@neerajdotname neerajdotname authored
Showing with 44 additions and 2 deletions.
  1. +2 −2 src/rails.js
  2. +42 −0 test/public/test/data-confirm.js
View
4 src/rails.js
@@ -70,7 +70,7 @@ jQuery(function ($) {
var jqueryVersion = $().jquery;
if ( (jqueryVersion === '1.4') || (jqueryVersion === '1.4.1') || (jqueryVersion === '1.4.2')){
- $('a[data-confirm],input[data-confirm]').live('click', function () {
+ $('a[data-confirm], button[data-confirm], input[data-confirm]').live('click', function () {
var el = $(this);
if (el.triggerAndReturn('confirm')) {
if (!confirm(el.attr('data-confirm'))) {
@@ -79,7 +79,7 @@ jQuery(function ($) {
}
});
} else {
- $('body').delegate('a[data-confirm],input[data-confirm]', 'click', function () {
+ $('body').delegate('a[data-confirm], button[data-confirm], input[data-confirm]', 'click', function () {
var el = $(this);
if (el.triggerAndReturn('confirm')) {
if (!confirm(el.attr('data-confirm'))) {
View
42 test/public/test/data-confirm.js
@@ -20,6 +20,16 @@ module('data-confirm', {
value: 'Click me'
}));
+
+ $('#fixtures').append($('<button />', {
+ 'data-confirm': App.confirmation_message,
+ 'data-remote': 'true',
+ href: App.url('show'),
+ name: 'submit',
+ type: 'button',
+ value: 'Click me'
+ }));
+
}
});
@@ -125,3 +135,35 @@ test('clicking on Submit input tag with data-confirm attribute. Confirm no.', fu
}, 100);
});
+
+test('clicking on button tag with data-confirm attribute. Confirm yes.', function() {
+ expect(1);
+
+ window.confirm = function(msg) {
+ $(document.body).data('confirmation-message', msg);
+ return true;
+ };
+
+ $('button[data-confirm]').trigger('click');
+
+ //clicking a button does not submit anything. Just assert that confirmation message was same.
+ equals( $(document.body).data('confirmation-message'),
+ App.confirmation_message,
+ 'confirmation message should be same');
+});
+
+test('clicking on a button tag with data-confirm attribute. Confirm no.', function() {
+ expect(1);
+
+ window.confirm = function(msg) {
+ $(document.body).data('confirmation-message', msg);
+ return false;
+ };
+
+ $('button[data-confirm]').trigger('click');
+
+ equals( $(document.body).data('confirmation-message'),
+ App.confirmation_message,
+ 'confirmation message should be same');
+
+});
Please sign in to comment.
Something went wrong with that request. Please try again.