Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#15221 closed bug (notabug)

Button disabled when initialized with falsy 0

Reported by: heinrichmartin Owned by:
Priority: minor Milestone: none
Component: ui.core Version: 1.12.1
Keywords: Cc:
Blocked by: Blocking:


When creating a button with disabled=0 then ui-state-disabled is applied.

Minimum Example

minimum example of jquery-ui bug:
"disabled" to be strict boolean for css class toggling
<link rel="stylesheet" type="text/css" href="jquery-ui-1.12.1/jquery-ui.css"></link>
<h1>Note that ui-state-disabled and ui-button-disabled are out-of-sync on the first button</h1>
<button>I am enabled</button>
<button>Me too</button>
<button>I am disabled</button>
<button>Me too</button>
<script src="jquery-3.2.1.js" type="text/javascript"></script>
<script src="jquery-ui-1.12.1/jquery-ui.js" type="text/javascript"></script>
<script type="text/javascript">
      disabled: 0
      disabled: false
      disabled: 42
      disabled: true


jquery-ui.js has three occurrences of calls to _toggleClass with the value of the disabled option being forwarded as-is. Some other occurrences already have the conversion to boolean included.

_toggleClass however uses this parameter for animation when it is not strictly boolean.

I have no build environment for jquery-ui, but I fixed it directly by adding the conversion to boolean "!!".


Set option "disabled" to strict boolean.

Change History (2)

comment:1 Changed 5 years ago by Scott González

Resolution: notabug
Status: newclosed

Set option "disabled" to strict boolean.

Not so much a workaround as the only supported type of value:

comment:2 in reply to:  1 Changed 5 years ago by heinrichmartin

Replying to Scott González:

Not so much a workaround as the only supported type of value:

Well, then why does $('button').eq(2).button('option','disabled') return 42?

Imho a mature and reliable library should be either tolerant or fail fast.

Note: See TracTickets for help on using tickets.