Search and Top Navigation
#15221 closed bug (notabug)
Opened July 21, 2017 07:56PM UTC
Closed July 21, 2017 08:07PM UTC
Last modified July 21, 2017 11:16PM UTC
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: |
Description
When creating a button with disabled=0
then ui-state-disabled is applied.
Minimum Example
<html> <!-- minimum example of jquery-ui bug: "disabled" to be strict boolean for css class toggling --> <head> <title>Button</title> <link rel="stylesheet" type="text/css" href="jquery-ui-1.12.1/jquery-ui.css"></link> </head> <body> <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"> $(function(){ $('button').eq(0).button({ disabled: 0 }).end().eq(1).button({ disabled: false }).end().eq(2).button({ disabled: 42 }).end().eq(3).button({ disabled: true }); }) </script> </body> </html>
Analysis
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 "!!".
Workaround
Set option "disabled" to strict boolean.
Attachments (0)
Change History (2)
Changed July 21, 2017 08:07PM UTC by comment:1
resolution: | → notabug |
---|---|
status: | new → closed |
Changed July 21, 2017 11:16PM UTC by comment:2
Replying to [comment:1 Scott González]:
Not so much a workaround as the only supported type of value: http://api.jqueryui.com/button/#option-disabled
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.
Not so much a workaround as the only supported type of value: http://api.jqueryui.com/button/#option-disabled