]> source.dussan.org Git - jquery-ui.git/commitdiff
Button: Fixing handling of the disabled options on refresh method calls. Fixed ...
authorTJ VanToll <tj.vantoll@gmail.com>
Mon, 19 Nov 2012 20:42:28 +0000 (15:42 -0500)
committerJörn Zaefferer <joern.zaefferer@gmail.com>
Fri, 23 Nov 2012 10:09:07 +0000 (11:09 +0100)
(cherry picked from commit 93abe02b6052143fac30393291da3fc254bde996)

tests/unit/button/button_methods.js
tests/unit/button/button_tickets.js
ui/jquery.ui.button.js

index 6a305d654ec67f4533df0dba420b632eba010f6d..c534440057eb709a2b9640bc507c1d93d7e9c7b1 100644 (file)
@@ -13,4 +13,40 @@ test("destroy", function() {
        });
 });
 
+test( "refresh: Ensure disabled state is preserved correctly.", function() {
+       expect( 8 );
+       
+       var element = $( "<a href='#'></a>" );
+       element.button({ disabled: true }).button( "refresh" );
+       ok( element.button( "option", "disabled" ), "Anchor button should remain disabled after refresh" ); //See #8237
+
+       element = $( "<div></div>" );
+       element.button({ disabled: true }).button( "refresh" );
+       ok( element.button( "option", "disabled" ), "<div> buttons should remain disabled after refresh" );
+
+       element = $( "<button></button>" );
+       element.button( { disabled: true} ).button( "refresh" );
+       ok( element.button( "option", "disabled" ), "<button> should remain disabled after refresh");
+
+       element = $( "<input type='checkbox'>" );
+       element.button( { disabled: true} ).button( "refresh" );
+       ok( element.button( "option", "disabled" ), "Checkboxes should remain disabled after refresh");
+
+       element = $( "<input type='radio'>" );
+       element.button( { disabled: true} ).button( "refresh" );
+       ok( element.button( "option", "disabled" ), "Radio buttons should remain disabled after refresh");
+
+       element = $( "<button></button>" );
+       element.button( { disabled: true} ).prop( "disabled", false ).button( "refresh" );
+       ok( !element.button( "option", "disabled" ), "Changing a <button>'s disabled property should update the state after refresh."); //See #8828
+
+       element = $( "<input type='checkbox'>" );
+       element.button( { disabled: true} ).prop( "disabled", false ).button( "refresh" );
+       ok( !element.button( "option", "disabled" ), "Changing a checkbox's disabled property should update the state after refresh.");
+
+       element = $( "<input type='radio'>" );
+       element.button( { disabled: true} ).prop( "disabled", false ).button( "refresh" );
+       ok( !element.button( "option", "disabled" ), "Changing a radio button's disabled property should update the state after refresh.");
+});
+
 })(jQuery);
index 1e901f9d10c2adca304cf2f4948fd875ea1edcd9..1272d368fb5f5e39e9d70e58d93038cd63df0d78 100644 (file)
@@ -72,12 +72,4 @@ test( "#7534 - Button label selector works for ids with \":\"", function() {
        ok( group.find( "label" ).is( ".ui-button" ), "Found an id with a :" );
 });
 
-test( "#8237 - Anchor tags lose disabled state when refreshed", function() {
-       expect( 1 );
-       var element = $( "<a id='a8237'></a>" ).appendTo( "#qunit-fixture" );
-
-       element.button({ disabled: true }).button( "refresh" );
-       ok( element.button( "option", "disabled" ), "Anchor button should remain disabled after refresh" );
-});
-
 })( jQuery );
index 6363bcdcb182aaaeec3cf78d14c83197e1e90cf5..673cd3fbf5f81975820ad4dd4ef822e6454a8d6a 100644 (file)
@@ -283,7 +283,9 @@ $.widget( "ui.button", {
        },
 
        refresh: function() {
-               var isDisabled = this.element.is( ":disabled" ) || this.element.hasClass( "ui-button-disabled" );
+               //See #8237 & #8828
+               var isDisabled = this.element.is( "input, button" ) ? this.element.is( ":disabled" ) : this.element.hasClass( "ui-button-disabled" );
+
                if ( isDisabled !== this.options.disabled ) {
                        this._setOption( "disabled", isDisabled );
                }