Skip to content

Commit 0059722

Browse files
committed
Button: Properly refresh button sets with new radio buttons
Fixes #8975 Ref gh-888
1 parent f3ffc8c commit 0059722

File tree

3 files changed

+37
-8
lines changed

3 files changed

+37
-8
lines changed

tests/unit/button/button.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@
4040
<input type="radio" id="radio02" name="radio"><label for="radio02">Choice 2</label>
4141
<input type="radio" id="radio03" name="radio"><label for="radio03">Choice 3</label>
4242
</div>
43+
<div id="checkbox0">
44+
<input type="checkbox" id="checkbox01" name="checkbox"><label for="checkbox01">Choice 1</label>
45+
<input type="checkbox" id="checkbox02" name="checkbox"><label for="checkbox02">Choice 2</label>
46+
<input type="checkbox" id="checkbox03" name="checkbox"><label for="checkbox03">Choice 3</label>
47+
</div>
4348
<form>
4449
<div id="radio1" style="margin-top: 2em;">
4550
<input type="radio" id="radio11" name="radio"><label for="radio11">Choice 1</label>

tests/unit/button/button_methods.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,26 @@ test( "refresh: Ensure disabled state is preserved correctly.", function() {
4949
ok( !element.button( "option", "disabled" ), "Changing a radio button's disabled property should update the state after refresh.");
5050
});
5151

52+
// #8975
53+
test( "refresh: buttonset should turn added elements into button widgets", function() {
54+
expect( 2 );
55+
var radioButtonset = $( "#radio0" ).buttonset(),
56+
checkboxButtonset = $( "#checkbox0" ).buttonset();
57+
58+
radioButtonset.append(
59+
"<input type='radio' name='radio' id='radio04'>" +
60+
"<label for='radio04'>Choice 4</label>"
61+
);
62+
checkboxButtonset.append(
63+
"<input type='checkbox' name='checkbox' id='checkbox04'>" +
64+
"<label for='checkbox04'>Choice 4</label>"
65+
);
66+
67+
radioButtonset.buttonset( "refresh" );
68+
checkboxButtonset.buttonset( "refresh" );
69+
70+
equal( radioButtonset.find( ":ui-button" ).length, 4, "radio" );
71+
equal( checkboxButtonset.find( ":ui-button" ).length, 4, "checkbox" );
72+
});
73+
5274
})(jQuery);

ui/button.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -366,15 +366,17 @@ $.widget( "ui.buttonset", {
366366
},
367367

368368
refresh: function() {
369-
var rtl = this.element.css( "direction" ) === "rtl";
369+
var rtl = this.element.css( "direction" ) === "rtl",
370+
allButtons = this.element.find( this.options.items ),
371+
existingButtons = allButtons.filter( ":ui-button" );
370372

371-
this.buttons = this.element.find( this.options.items )
372-
.filter( ":ui-button" )
373-
.button( "refresh" )
374-
.end()
375-
.not( ":ui-button" )
376-
.button()
377-
.end()
373+
// Initialize new buttons
374+
allButtons.not( ":ui-button" ).button();
375+
376+
// Refresh existing buttons
377+
existingButtons.button( "refresh" );
378+
379+
this.buttons = allButtons
378380
.map(function() {
379381
return $( this ).button( "widget" )[ 0 ];
380382
})

0 commit comments

Comments
 (0)