Permalink
Browse files

Added double quotes to radio attribute name to account for characters…

… such as brackets
  • Loading branch information...
1 parent 73751dc commit 2bf7bffe0fa8cde131293f4d271f917d739c91e7 @akant10 akant10 committed with davidchambers Jun 24, 2014
Showing with 6 additions and 1 deletion.
  1. +1 −1 lib/api/attributes.js
  2. +4 −0 test/api.attributes.js
  3. +1 −0 test/fixtures.js
View
@@ -166,7 +166,7 @@ var val = exports.val = function(value) {
case 'input':
switch (this.attr('type')) {
case 'radio':
- var queryString = 'input[type=radio][name=' + this.attr('name') + ']:checked';
+ var queryString = 'input[type=radio][name="' + this.attr('name') + '"]:checked';
var parentEl, root;
// Go up until we hit a form or root
View
@@ -321,6 +321,10 @@ describe('$(...)', function() {
var element = $('input[name="radio"]').val('off');
expect(element.val()).to.equal('off');
});
+ it('.val(value): on radio with special characters should set value', function() {
+ var element = $('input[name="radio[brackets]"]').val('off');
+ expect(element.val()).to.equal('off');
+ });
it('.val(values): on multiple select should set multiple values', function() {
var element = $('select#multi').val(['1', '3', '4']);
expect(element.val()).to.have.length(3);
View
@@ -44,6 +44,7 @@ exports.inputs = [
'<input type="text" value="input_text" />',
'<input type="checkbox" name="checkbox_off" value="off" /><input type="checkbox" name="checkbox_on" value="on" checked />',
'<input type="radio" value="off" name="radio" /><input type="radio" name="radio" value="on" checked />',
+ '<input type="radio" value="off" name="radio[brackets]" /><input type="radio" name="radio[brackets]" value="on" checked />',
'<select id="multi" multiple><option value="1">1</option><option value="2" selected>2</option><option value="3" selected>3</option><option value="4">4</option></select>'
].join('');

0 comments on commit 2bf7bff

Please sign in to comment.