Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

… such as brackets
  • Loading branch information...
commit 2bf7bffe0fa8cde131293f4d271f917d739c91e7 1 parent 73751dc
@akant10 akant10 authored davidchambers committed
View
2  lib/api/attributes.js
@@ -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
4 test/api.attributes.js
@@ -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
1  test/fixtures.js
@@ -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('');
Please sign in to comment.
Something went wrong with that request. Please try again.