Skip to content

Commit cf96e47

Browse files
committed
Adding support for the novalidate form attribute. A form with this attribute should not force the html5 validation on its required=required fields. Test included.
1 parent 8571154 commit cf96e47

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/rails.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@
287287
if (!rails.allowAction(form)) return rails.stopEverything(e);
288288

289289
// skip other logic when required values are missing or file upload is present
290-
if (blankRequiredInputs && rails.fire(form, 'ajax:aborted:required', [blankRequiredInputs])) {
290+
if (blankRequiredInputs && rails.fire(form, 'ajax:aborted:required', [blankRequiredInputs]) && form.attr("novalidate") == undefined) {
291291
return rails.stopEverything(e);
292292
}
293293

test/public/test/call-remote-callbacks.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,38 @@ asyncTest('disabled fields should not be included in blank required check', 1, f
137137
}, 13);
138138
});
139139

140+
asyncTest('form should be submitted with blank required fields if it has the "novalidate" attribute', 2, function(){
141+
var form = $('form[data-remote]')
142+
.append($('<input type="text" name="user_name" required="required">'))
143+
.attr("novalidate", "novalidate")
144+
.bind('ajax:beforeSend', function() {
145+
ok(true, 'ajax:beforeSend should run');
146+
})
147+
.bind('ajax:complete', function() {
148+
ok(true, 'ajax:complete should run')
149+
})
150+
.trigger('submit');
151+
152+
setTimeout(function() {
153+
start();
154+
}, 13);
155+
});
156+
157+
asyncTest('blank required form input for non-remote form with "novalidate" attribute should not abort normal submission', 1, function() {
158+
var form = $('form[data-remote]')
159+
.append($('<input type="text" name="user_name" required="required">'))
160+
.removeAttr('data-remote')
161+
.attr("novalidate","novalidate")
162+
.bind('iframe:loading', function() {
163+
ok(true, 'form should get submitted');
164+
})
165+
.trigger('submit');
166+
167+
setTimeout(function() {
168+
start();
169+
}, 13);
170+
});
171+
140172
function skipIt() {
141173
// This test cannot work due to the security feature in browsers which makes the value
142174
// attribute of file input fields readonly, so it cannot be set with default value.

0 commit comments

Comments
 (0)