From 0059722b6b43c4985dbbd5f1494524442c12ddb0 Mon Sep 17 00:00:00 2001 From: Scott González Date: Tue, 1 Apr 2014 14:42:38 -0400 Subject: Button: Properly refresh button sets with new radio buttons Fixes #8975 Ref gh-888 --- tests/unit/button/button.html | 5 +++++ tests/unit/button/button_methods.js | 22 ++++++++++++++++++++++ ui/button.js | 18 ++++++++++-------- 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/tests/unit/button/button.html b/tests/unit/button/button.html index e016a06b0..a6ff8fc61 100644 --- a/tests/unit/button/button.html +++ b/tests/unit/button/button.html @@ -40,6 +40,11 @@ +
+ + + +
diff --git a/tests/unit/button/button_methods.js b/tests/unit/button/button_methods.js index 467938f00..1c781c87e 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."); }); +// #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, "radio" ); + equal( checkboxButtonset.find( ":ui-button" ).length, 4, "checkbox" ); +}); + })(jQuery); diff --git a/ui/button.js b/ui/button.js index d9b027541..247aba6e5 100644 --- a/ui/button.js +++ b/ui/button.js @@ -366,15 +366,17 @@ $.widget( "ui.buttonset", { }, refresh: function() { - var rtl = this.element.css( "direction" ) === "rtl"; + var rtl = this.element.css( "direction" ) === "rtl", + allButtons = this.element.find( this.options.items ), + existingButtons = allButtons.filter( ":ui-button" ); - this.buttons = this.element.find( this.options.items ) - .filter( ":ui-button" ) - .button( "refresh" ) - .end() - .not( ":ui-button" ) - .button() - .end() + // Initialize new buttons + allButtons.not( ":ui-button" ).button(); + + // Refresh existing buttons + existingButtons.button( "refresh" ); + + this.buttons = allButtons .map(function() { return $( this ).button( "widget" )[ 0 ]; }) -- cgit v1.2.3