@@ -26,7 +26,7 @@ module('data-disable', {
26
26
text : 'Click me' ,
27
27
'data-remote' : true ,
28
28
'data-url' : '/echo' ,
29
- 'data-disable-with ' : 'clicking... '
29
+ 'data-disable' : 'true '
30
30
} ) ) ;
31
31
} ,
32
32
teardown : function ( ) {
@@ -251,3 +251,74 @@ asyncTest('ctrl-clicking on a link does not disables the link', 6, function() {
251
251
App . checkEnabledState ( link , 'Click me' ) ;
252
252
start ( ) ;
253
253
} ) ;
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