From 2838c11ea8fa1bd8dfffe27a6e28dee6d3e0d423 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Scott=20Gonz=C3=A1lez?= Date: Wed, 18 Aug 2010 14:51:30 -0400 Subject: [PATCH] Button: Read disabled attribute from original element if disabled option is null. Fixes #5252 -Button: read disabled option from input elements. --- tests/unit/button/button_defaults.js | 2 +- tests/unit/button/button_options.js | 24 ++++++++++++++++++++++++ ui/jquery.ui.button.js | 5 +++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/tests/unit/button/button_defaults.js b/tests/unit/button/button_defaults.js index e1657854a..b81fa7cbb 100644 --- a/tests/unit/button/button_defaults.js +++ b/tests/unit/button/button_defaults.js @@ -3,7 +3,7 @@ */ var button_defaults = { - disabled: false, + disabled: null, text: true, label: null, icons: { diff --git a/tests/unit/button/button_options.js b/tests/unit/button/button_options.js index 6ee8ab541..5b25ecd63 100644 --- a/tests/unit/button/button_options.js +++ b/tests/unit/button/button_options.js @@ -5,6 +5,30 @@ module("button: options"); +test("disabled, explicity value", function() { + $("#radio01").button({ disabled: false }); + same(false, $("#radio01").button("option", "disabled"), + "disabled option set to false"); + same(false, $("#radio01").attr("disabled"), "element is disabled"); + + $("#radio02").button({ disabled: true }); + same(true, $("#radio02").button("option", "disabled"), + "disabled option set to true"); + same(true, $("#radio02").attr("disabled"), "element is not disabled"); +}); + +test("disabled, null", function() { + $("#radio01").button({ disabled: null }); + same(false, $("#radio01").button("option", "disabled"), + "disabled option set to false"); + same(false, $("#radio01").attr("disabled"), "element is disabled"); + + $("#radio02").attr("disabled", "disabled").button({ disabled: null }); + same(true, $("#radio02").button("option", "disabled"), + "disabled option set to true"); + same(true, $("#radio02").attr("disabled"), "element is not disabled"); +}); + test("text false without icon", function() { $("#button").button({ text: false diff --git a/ui/jquery.ui.button.js b/ui/jquery.ui.button.js index 7d21fa495..5e52fb4cb 100644 --- a/ui/jquery.ui.button.js +++ b/ui/jquery.ui.button.js @@ -44,6 +44,7 @@ var lastActive, $.widget( "ui.button", { options: { + disabled: null, text: true, label: null, icons: { @@ -56,6 +57,10 @@ $.widget( "ui.button", { .unbind( "reset.button" ) .bind( "reset.button", formResetHandler ); + if ( typeof this.options.disabled !== "boolean" ) { + this.options.disabled = this.element.attr( "disabled" ); + } + this._determineButtonType(); this.hasTitle = !!this.buttonElement.attr( "title" );