Skip to content

Commit d717eeb

Browse files
committed
Merge branch 'master' into data-disable
Conflicts: src/rails.js test/public/test/data-disable.js
2 parents 693ccdf + 1b4882b commit d717eeb

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

src/rails.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,20 @@
185185
form.submit();
186186
},
187187

188+
// Helper function that returns form elements that match the specified CSS selector
189+
// If form is actually a "form" element this will return associated elements outside the from that have
190+
// the html form attribute set
191+
formElements: function(form, selector) {
192+
return form.is('form') ? $(form[0].elements).filter(selector) : form.find(selector)
193+
},
194+
188195
/* Disables form elements:
189196
- Caches element value in 'ujs:enable-with' data store
190197
- Replaces element text with value of 'data-disable-with' attribute
191198
- Sets disabled property to true
192199
*/
193200
disableFormElements: function(form) {
194-
form.find(rails.disableSelector).each(function() {
201+
rails.formElements(form, rails.disableSelector).each(function() {
195202
var element, method, replacement;
196203

197204
element = $(this);
@@ -212,7 +219,7 @@
212219
- Sets disabled property to false
213220
*/
214221
enableFormElements: function(form) {
215-
form.find(rails.enableSelector).each(function() {
222+
rails.formElements(form, rails.enableSelector).each(function() {
216223
var element = $(this), method = element.is('button') ? 'html' : 'val';
217224
if (element.data('ujs:enable-with')) element[method](element.data('ujs:enable-with'));
218225
element.prop('disabled', false);

test/public/test/data-disable-with.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ module('data-disable-with', {
1010

1111
$('#qunit-fixture').append($('<form />', {
1212
action: '/echo',
13-
method: 'post'
13+
method: 'post',
14+
id: 'not_remote'
1415
}))
1516
.find('form:last')
1617
// WEEIRDD: the form won't submit to an iframe if the button is name="submit" (??!)
@@ -21,6 +22,15 @@ module('data-disable-with', {
2122
href: '/echo',
2223
'data-disable-with': 'clicking...'
2324
}));
25+
26+
27+
$('#qunit-fixture').append($('<input />', {
28+
type: 'submit',
29+
form: 'not_remote',
30+
'data-disable-with': 'form attr submitting',
31+
name: 'submit3',
32+
value: 'Form Attr Submit'
33+
}));
2434
},
2535
teardown: function() {
2636
$(document).unbind('iframe:loaded');
@@ -110,6 +120,27 @@ asyncTest('form[data-remote] input[data-disable-with] is replaced with disabled
110120
}).trigger('submit');
111121
});
112122

123+
asyncTest('form input[type=submit][data-disable-with] using "form" attribute disables', 6, function() {
124+
var form = $('#not_remote'), input = $('input[form=not_remote]');
125+
App.checkEnabledState(input, 'Form Attr Submit');
126+
127+
// WEEIRDD: attaching this handler makes the test work in IE7
128+
$(document).bind('iframe:loading', function(e, form) {});
129+
130+
$(document).bind('iframe:loaded', function(e, data) {
131+
setTimeout(function() {
132+
App.checkDisabledState(input, 'form attr submitting');
133+
start();
134+
}, 30);
135+
});
136+
form.trigger('submit');
137+
138+
setTimeout(function() {
139+
App.checkDisabledState(input, 'form attr submitting');
140+
}, 30);
141+
142+
});
143+
113144
asyncTest('form[data-remote] textarea[data-disable-with] attribute', 3, function() {
114145
var form = $('form[data-remote]'),
115146
textarea = $('<textarea data-disable-with="processing ..." name="user_bio">born, lived, died.</textarea>').appendTo(form);

0 commit comments

Comments
 (0)