Skip to content
This repository was archived by the owner on Oct 8, 2021. It is now read-only.

Commit 5bb9ee8

Browse files
author
Gabriel Schulhof
committed
Button: Sync disabled state upon refresh()
Fixes gh-7139
1 parent bfbdebb commit 5bb9ee8

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

js/widgets/forms/button.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,19 @@ $.widget( "mobile.button", {
126126
},
127127

128128
refresh: function( create ) {
129+
var originalElement,
130+
isDisabled = this.element.prop( "disabled" );
131+
129132
if ( this.options.icon && this.options.iconpos === "notext" && this.element.attr( "title" ) ) {
130133
this.element.attr( "title", this.element.val() );
131134
}
132135
if ( !create ) {
133-
var originalElement = this.element.detach();
136+
originalElement = this.element.detach();
134137
$( this.wrapper ).text( this.element.val() ).append( originalElement );
135138
}
139+
if ( this.options.disabled !== isDisabled ) {
140+
this._setOptions({ disabled: isDisabled });
141+
}
136142
}
137143
});
138144

tests/unit/button/button_core.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,14 @@
4444
ok( $htmlstring.find("sup").length, "HTML contained within a button element should carry over to the enhanced version" );
4545
});
4646

47+
test( "Button's disabled state synced via refresh()", function() {
48+
var button = $( "#disabled-state" );
49+
50+
button.prop( "disabled", true ).button( "refresh" );
51+
52+
deepEqual( button.parent().hasClass( "ui-state-disabled" ), true,
53+
"class ui-state-disabled has been added to the wrapper" );
54+
deepEqual( button.button( "option", "disabled" ), true, "option disabled is now true" );
55+
});
56+
4757
})( jQuery );

tests/unit/button/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
<button id="theme-check-explicit" value="foo" data-nstest-theme="a"></button>
6565
<button id="contains-html">Supports <sup>phrasing content</sup></button>
6666
<input type="button" id="val-contains-html" value="<fake markup>"/>
67+
<input type="button" id="disabled-state" value="ABC"/>
6768
</div>
6869
</div>
6970
</body>

0 commit comments

Comments
 (0)