Skip to content

Commit becb822

Browse files
committed
Added support for button[data-disable].
1 parent f1a4b36 commit becb822

File tree

2 files changed

+73
-2
lines changed

2 files changed

+73
-2
lines changed

src/rails.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
linkDisableSelector: 'a[data-disable-with], a[data-disable]',
5353

5454
// Button onClick disable selector with possible reenable after remote submission
55-
buttonDisableSelector: 'button[data-remote][data-disable-with]',
55+
buttonDisableSelector: 'button[data-remote][data-disable-with], button[data-remote][data-disable]',
5656

5757
// Make sure that every Ajax request sends the CSRF token
5858
CSRFProtection: function(xhr) {

test/public/test/data-disable.js

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module('data-disable', {
2626
text: 'Click me',
2727
'data-remote': true,
2828
'data-url': '/echo',
29-
'data-disable-with': 'clicking...'
29+
'data-disable': 'true'
3030
}));
3131
},
3232
teardown: function() {
@@ -251,3 +251,74 @@ asyncTest('ctrl-clicking on a link does not disables the link', 6, function() {
251251
App.checkEnabledState(link, 'Click me');
252252
start();
253253
});
254+
255+
asyncTest('button[data-remote][data-disable] disables and re-enables', 6, function() {
256+
var button = $('button[data-remote][data-disable]');
257+
258+
App.checkEnabledState(button, 'Click me');
259+
260+
button
261+
.bind('ajax:send', function() {
262+
App.checkDisabledState(button, 'Click me');
263+
})
264+
.bind('ajax:complete', function() {
265+
setTimeout( function() {
266+
App.checkEnabledState(button, 'Click me');
267+
start();
268+
}, 15);
269+
})
270+
.trigger('click');
271+
});
272+
273+
asyncTest('button[data-remote][data-disable] re-enables when `ajax:before` event is cancelled', 6, function() {
274+
var button = $('button[data-remote][data-disable]');
275+
276+
App.checkEnabledState(button, 'Click me');
277+
278+
button
279+
.bind('ajax:before', function() {
280+
App.checkDisabledState(button, 'Click me');
281+
return false;
282+
})
283+
.trigger('click');
284+
285+
setTimeout(function() {
286+
App.checkEnabledState(button, 'Click me');
287+
start();
288+
}, 30);
289+
});
290+
291+
asyncTest('button[data-remote][data-disable] re-enables when `ajax:beforeSend` event is cancelled', 6, function() {
292+
var button = $('button[data-remote][data-disable]');
293+
294+
App.checkEnabledState(button, 'Click me');
295+
296+
button
297+
.bind('ajax:beforeSend', function() {
298+
App.checkDisabledState(button, 'Click me');
299+
return false;
300+
})
301+
.trigger('click');
302+
303+
setTimeout(function() {
304+
App.checkEnabledState(button, 'Click me');
305+
start();
306+
}, 30);
307+
});
308+
309+
asyncTest('button[data-remote][data-disable] re-enables when `ajax:error` event is triggered', 6, function() {
310+
var button = $('a[data-disable]').attr('data-remote', true).attr('href', '/error');
311+
312+
App.checkEnabledState(button, 'Click me');
313+
314+
button
315+
.bind('ajax:send', function() {
316+
App.checkDisabledState(button, 'Click me');
317+
})
318+
.trigger('click');
319+
320+
setTimeout(function() {
321+
App.checkEnabledState(button, 'Click me');
322+
start();
323+
}, 30);
324+
});

0 commit comments

Comments
 (0)