From ccb13240dd8b5cfac0199a30dcec4a71cbe1b252 Mon Sep 17 00:00:00 2001 From: TJ VanToll Date: Tue, 28 Jan 2014 10:46:23 -0500 Subject: [PATCH] Button: Ignore non-radio elements with the same name Fixes #8761 Closes gh-1185 --- tests/unit/button/button_core.js | 14 ++++++++++++++ ui/button.js | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/tests/unit/button/button_core.js b/tests/unit/button/button_core.js index 41623e08d..f647cdc26 100644 --- a/tests/unit/button/button_core.js +++ b/tests/unit/button/button_core.js @@ -53,6 +53,20 @@ test("radio groups", function() { assert(":eq(1)", ":eq(0)", ":eq(0)"); }); +test( "radio groups - ignore elements with same name", function() { + expect( 1 ); + var form = $( "form:first" ), + radios = form.find( "[type=radio]" ).button(), + checkbox = $( "", { + type: "checkbox", + name: radios.attr( "name" ) + }); + + form.append( checkbox ); + radios.button( "refresh" ); + ok( true, "no exception from accessing button instance of checkbox" ); +}); + test("input type submit, don't create child elements", function() { expect( 2 ); var input = $("#submit"); diff --git a/ui/button.js b/ui/button.js index 4b401e1a3..96fea440f 100644 --- a/ui/button.js +++ b/ui/button.js @@ -40,9 +40,9 @@ var lastActive, if ( name ) { name = name.replace( /'/g, "\\'" ); if ( form ) { - radios = $( form ).find( "[name='" + name + "']" ); + radios = $( form ).find( "[name='" + name + "'][type=radio]" ); } else { - radios = $( "[name='" + name + "']", radio.ownerDocument ) + radios = $( "[name='" + name + "'][type=radio]", radio.ownerDocument ) .filter(function() { return !this.form; });