Skip to content

Commit 2de31fd

Browse files
committed
Button: On form reset only call refresh on current button widgets. Fixed #9213: Button: timeout in formResetHandler causing refresh to be called on non-widgets
1 parent 5b9e6a4 commit 2de31fd

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

tests/unit/button/button_core.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,30 @@ test( "#6262 - buttonset not applying ui-corner to invisible elements", function
153153
ok( set.find( "label:eq(2)" ).is( ".ui-button.ui-corner-right" ) );
154154
});
155155

156+
asyncTest( "Resetting a button's form should refresh the visual state of the button widget to match.", function() {
157+
expect( 2 );
158+
var form = $( "<form>" +
159+
"<button></button>" +
160+
"<label for='c1'></label><input id='c1' type='checkbox' checked>" +
161+
"</form>" ),
162+
button = form.find( "button" ).button(),
163+
checkbox = form.find( "input[type=checkbox]" ).button();
164+
165+
checkbox.prop( "checked", false ).button( "refresh" );
166+
ok( !checkbox.button( "widget" ).hasClass( "ui-state-active" ) );
167+
168+
form.get( 0 ).reset();
169+
170+
// #9213: If a button has been removed, refresh should not be called on it when
171+
// its corresponding form is reset.
172+
button.remove();
173+
174+
setTimeout(function() {
175+
ok( checkbox.button( "widget" ).hasClass( "ui-state-active" ));
176+
start();
177+
});
178+
});
179+
156180
asyncTest( "#6711 Checkbox/Radiobutton do not Show Focused State when using Keyboard Navigation", function() {
157181
expect( 2 );
158182
var check = $( "#check" ).button(),

ui/jquery.ui.button.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ var lastActive, startXPos, startYPos, clickDragged,
1919
stateClasses = "ui-state-hover ui-state-active ",
2020
typeClasses = "ui-button-icons-only ui-button-icon-only ui-button-text-icons ui-button-text-icon-primary ui-button-text-icon-secondary ui-button-text-only",
2121
formResetHandler = function() {
22-
var buttons = $( this ).find( ":ui-button" );
22+
var form = $( this );
2323
setTimeout(function() {
24-
buttons.button( "refresh" );
24+
form.find( ":ui-button" ).button( "refresh" );
2525
}, 1 );
2626
},
2727
radioGroup = function( radio ) {

0 commit comments

Comments
 (0)