From ab440f688b13e5a177ad01c4059a07310a41af12 Mon Sep 17 00:00:00 2001 From: TJ VanToll Date: Sat, 19 Jan 2013 22:42:25 -0500 Subject: [PATCH] Button: Newly added radios need to become UI buttons in refresh. Fixed #8975 - Buttonset: refresh method causes JS error after adding new radio buttons --- tests/unit/button/button.html | 5 +++++ tests/unit/button/button_methods.js | 22 ++++++++++++++++++++++ ui/jquery.ui.button.js | 6 ++++-- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/tests/unit/button/button.html b/tests/unit/button/button.html index eeb56868673..b15a37c6509 100644 --- a/tests/unit/button/button.html +++ b/tests/unit/button/button.html @@ -44,6 +44,11 @@

+
+ + + +
diff --git a/tests/unit/button/button_methods.js b/tests/unit/button/button_methods.js index c534440057e..191507f32b2 100644 --- a/tests/unit/button/button_methods.js +++ b/tests/unit/button/button_methods.js @@ -49,4 +49,26 @@ test( "refresh: Ensure disabled state is preserved correctly.", function() { ok( !element.button( "option", "disabled" ), "Changing a radio button's disabled property should update the state after refresh."); }); +// See #8975 +test("refresh: buttonset should turn added elements into button widgets.", function() { + expect( 2 ); + var radioButtonset = $("#radio0").buttonset(), + checkboxButtonset = $("#checkbox0").buttonset(); + + radioButtonset.append( + '' + + '' + ); + checkboxButtonset.append( + '' + + '' + ); + + radioButtonset.buttonset("refresh"); + checkboxButtonset.buttonset("refresh"); + + equal( radioButtonset.find(":ui-button").length, 4 ); + equal( checkboxButtonset.find(":ui-button").length, 4 ); +}); + })(jQuery); diff --git a/ui/jquery.ui.button.js b/ui/jquery.ui.button.js index fcb7b14d187..51f478525fd 100644 --- a/ui/jquery.ui.button.js +++ b/ui/jquery.ui.button.js @@ -293,11 +293,13 @@ $.widget( "ui.button", { if ( this.type === "radio" ) { radioGroup( this.element[0] ).each(function() { if ( $( this ).is( ":checked" ) ) { - $( this ).button( "widget" ) + $( this ).button() + .button( "widget" ) .addClass( "ui-state-active" ) .attr( "aria-pressed", "true" ); } else { - $( this ).button( "widget" ) + $( this ).button() + .button( "widget" ) .removeClass( "ui-state-active" ) .attr( "aria-pressed", "false" ); }