Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add handling on select[required] elements #458

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/rails.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
enableSelector: 'input[data-disable-with]:disabled, button[data-disable-with]:disabled, textarea[data-disable-with]:disabled, input[data-disable]:disabled, button[data-disable]:disabled, textarea[data-disable]:disabled',

// Form required input elements
requiredInputSelector: 'input[name][required]:not([disabled]), textarea[name][required]:not([disabled])',
requiredInputSelector: 'input[name][required]:not([disabled]), textarea[name][required]:not([disabled]), select[name][required]:not([disabled])',

// Form file input elements
fileInputSelector: 'input[type=file]:not([disabled])',
Expand Down
11 changes: 7 additions & 4 deletions test/public/test/call-remote-callbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,27 +110,29 @@ asyncTest('stopping the "ajax:beforeSend" event aborts the request', 1, function
});
});

asyncTest('blank required form input field should abort request and trigger "ajax:aborted:required" event', 5, function() {
asyncTest('blank required form input field should abort request and trigger "ajax:aborted:required" event', 6, function() {
$(document).bind('iframe:loading', function() {
ok(false, 'form should not get submitted');
});

var form = $('form[data-remote]')
.append($('<input type="text" name="user_name" required="required">'))
.append($('<textarea name="user_bio" required="required"></textarea>'))
.append($('<select name="dropdown_test" required="required"><option value="">-</option><option value="Tyler">Tyler</option></textarea>'))
.bind('ajax:beforeSend', function() {
ok(false, 'ajax:beforeSend should not run');
})
.bind('ajax:aborted:required', function(e,data){
ok(data.length == 2, 'ajax:aborted:required event is passed all blank required inputs (jQuery objects)');
ok(data.length == 3, 'ajax:aborted:required event is passed all blank required inputs (jQuery objects)');
ok(data.first().is('input[name="user_name"]') , 'ajax:aborted:required adds blank required input to data');
ok(data.last().is('textarea[name="user_bio"]'), 'ajax:aborted:required adds blank required textarea to data');
ok(data.eq(1).is('textarea[name="user_bio"]'), 'ajax:aborted:required adds blank required textarea to data');
ok(data.last().is('select[name="dropdown_test"]'), 'ajax:aborted:required adds blank required textarea to data');
ok(true, 'ajax:aborted:required should run');
})
.trigger('submit');

setTimeout(function() {
form.find('input[required],textarea[required]').val('Tyler');
form.find('input[required],textarea[required],select[required]').val('Tyler');
form.unbind('ajax:beforeSend');
submit();
}, 13);
Expand Down Expand Up @@ -170,6 +172,7 @@ asyncTest('disabled fields should not be included in blank required check', 2, f
var form = $('form[data-remote]')
.append($('<input type="text" name="user_name" required="required" disabled="disabled">'))
.append($('<textarea name="user_bio" required="required" disabled="disabled"></textarea>'))
.append($('<select name="dropdown_test" required="required" disabled="disabled"><option value="">-</option><option value="Tyler">Tyler</option></textarea>'))
.bind('ajax:beforeSend', function() {
ok(true, 'ajax:beforeSend should run');
})
Expand Down