]> source.dussan.org Git - jquery-ui.git/commitdiff
Button: Properly refresh button sets with new radio buttons
authorScott González <scott.gonzalez@gmail.com>
Tue, 1 Apr 2014 18:42:38 +0000 (14:42 -0400)
committerScott González <scott.gonzalez@gmail.com>
Tue, 1 Apr 2014 18:42:38 +0000 (14:42 -0400)
Fixes #8975
Ref gh-888

tests/unit/button/button.html
tests/unit/button/button_methods.js
ui/button.js

index e016a06b0fab7f3f92175c78f68f0e15fade5014..a6ff8fc614896d2d78da6db8ca2fe8393caff5e0 100644 (file)
        <input type="radio" id="radio02" name="radio"><label for="radio02">Choice 2</label>
        <input type="radio" id="radio03" name="radio"><label for="radio03">Choice 3</label>
 </div>
+<div id="checkbox0">
+       <input type="checkbox" id="checkbox01" name="checkbox"><label for="checkbox01">Choice 1</label>
+       <input type="checkbox" id="checkbox02" name="checkbox"><label for="checkbox02">Choice 2</label>
+       <input type="checkbox" id="checkbox03" name="checkbox"><label for="checkbox03">Choice 3</label>
+</div>
 <form>
        <div id="radio1" style="margin-top: 2em;">
                <input type="radio" id="radio11" name="radio"><label for="radio11">Choice 1</label>
index 467938f00f59b1db6b9137564d75f6e904ef6b7d..1c781c87e227a374d7c86963580e7c2ea5a18855 100644 (file)
@@ -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(
+               "<input type='radio' name='radio' id='radio04'>" +
+               "<label for='radio04'>Choice 4</label>"
+       );
+       checkboxButtonset.append(
+               "<input type='checkbox' name='checkbox' id='checkbox04'>" +
+               "<label for='checkbox04'>Choice 4</label>"
+       );
+
+       radioButtonset.buttonset( "refresh" );
+       checkboxButtonset.buttonset( "refresh" );
+
+       equal( radioButtonset.find( ":ui-button" ).length, 4, "radio" );
+       equal( checkboxButtonset.find( ":ui-button" ).length, 4, "checkbox" );
+});
+
 })(jQuery);
index d9b027541ef4b38f903646c98983f1c991ee45f3..247aba6e5e01f6a35180ca385f8408b599382373 100644 (file)
@@ -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 ];
                        })