Skip to main content

Bug Tracker

Side navigation

#14892 closed bug (migrated)

Opened March 14, 2014 05:15PM UTC

Closed October 21, 2014 12:31AM UTC

Unable to trigger a checkbox click immediately after changing disabled to false

Reported by: danspamable@gmail.com Owned by: danspamable@gmail.com
Priority: high Milestone: None
Component: event Version: 1.11.0-rc1
Keywords: Cc: miketaylr
Blocked by: Blocking:
Description

This bug occurs in Firefox but not Internet Explorer.

Code to reproduce:

<input id="chk" type="checkbox" disabled />
<label for="chk">Checkbox</label>
$('#chk').prop('disabled', false);
$('#chk').trigger('click');

(or see http://jsfiddle.net/kcLkZ/)

Expected results:

Checkbox is enabled and checked.

Actual results:

Checkbox is enabled but not checked.

Attachments (0)
Change History (16)

Changed March 16, 2014 03:41PM UTC by dmethvin comment:1

owner: → danspamable@gmail.com
status: newpending

This native seems to work consistently in that no browser alerts: http://jsfiddle.net/QF46h/

Do you want to just run the jQuery handlers? In that case use .triggerHandler(). If you actually want to have a click event fire on a disabled element that is in the control of the browser.

Changed March 16, 2014 06:05PM UTC by anonymous comment:2

@dmethvin,

I do not wish to have the click event fire for the disabled checkbox. I really do want to both enable the checkbox *and* check it. The user interface requires that.

At the moment, my workaround is to basically "hammer" the checkbox using setTimeout.

See my edits to http://jsfiddle.net/kcLkZ/

Changed March 16, 2014 06:08PM UTC by anonymous comment:3

Sorry, that should have been: jsfiddle.net/kcLkZ/1/

Changed March 16, 2014 06:09PM UTC by anonymous comment:4

Changed March 17, 2014 01:08PM UTC by dmethvin comment:5

resolution: → notabug
status: pendingclosed
I really do want to both enable the checkbox *and* check it.

So you don't want to click it, just check/disable it?

$("#chk").prop({disabled: false, checked: true});

If you need more help try the forum rather than the bug tracker.

Changed March 17, 2014 03:49PM UTC by anonymous comment:6

Replying to [comment:5 dmethvin]:

So you don't want to click it, just check/disable it?

No, I really want to enable it, check it, ''and'' call the click event handler for it. Check this revised fiddle: http://jsfiddle.net/kcLkZ/3/.

$("#chk").prop({disabled: false, checked: true});

This does not simulate the user checking the checkbox, it just changes the state without calling the click handler.

If you need more help try the forum rather than the bug tracker.

Can you please explain why you think this isn't a bug? Isn't one of the goals of jQuery to smooth out the differences between browsers? I've reported a behavior that works differently between Explorer and Firefox. That enough should be a concern. But also, aren't DOM changes supposed to be synchronous? If triggering a click can't be performed immediately after enabling a checkbox, something is not quite completing by the time the next line of code is executed.

I appreciate you trying to help with my particular case, but my primary goal was to let you know about this bug, not receive tech support. If you think the bug is low priority and choose not to fix it, that's fine, but I don't understand writing it off as "notabug". It's a bug.

Changed March 17, 2014 03:58PM UTC by dmethvin comment:7

It doesn't make sense to disable a check box, then expect something to happen when you click it. jQuery's goal is not to create consistent behavior from a sequence of actions that don't make sense.

Changed March 17, 2014 04:06PM UTC by dmethvin comment:8

resolution: notabug
status: closedreopened

Oh, NOW I get it. un-disable and then click.

Changed March 17, 2014 04:06PM UTC by dmethvin comment:9

component: unfiledevent
priority: undecidedhigh
status: reopenedopen

Changed March 17, 2014 05:19PM UTC by devuxer comment:10

Phew :)

Changed September 30, 2014 02:01PM UTC by dougrchamberlain comment:11

I'd be happy to look into this issue.

Changed September 30, 2014 03:54PM UTC by dmethvin comment:12

@dougrchamberlain Go for it, thanks!

Changed October 01, 2014 02:29PM UTC by dougrchamberlain comment:13

Okay, so I looked into this, and by using http://jsfiddle.net/kcLkZ/1/ in Firefox 32.0.3 it completely fails to mark the checkbox in versions < 1.11.0

It fails intermittently starting at version 1.10.1 and continues to fail intermittently through 1.x(edge) and it fails intermittently through all 2.x versions

Chaining the statements seems to reduce the number of failures, like in this jsfiddle http://jsfiddle.net/kcLkZ/8/ but it doesn't eliminate them

The chaining not being a valid workaround really surprised me since the object passed to .trigger() should have finished before returning the JQuery object. Since this is my first attempt at resolving an issue, I'm wondering where I should begin looking.

Changed October 01, 2014 04:10PM UTC by dmethvin comment:14

cc: → miketaylr

This seems like a Firefox bug, which happens even with no jQuery involved.

http://jsfiddle.net/kcLkZ/10/

The problem goes away if the DOM .click() method is called asynchronously.

http://jsfiddle.net/kcLkZ/11/

Changed October 02, 2014 12:20PM UTC by dougrchamberlain comment:15

_comment0: True, I agree it is a firefox bug. But, does this mean it does not get fixed in JQuery? Let me know, because I have some ideas on how to resolve this. When making JQuery, cross browser compliant, is code created that checks the browser? Couldn't we just check for Firefox, and wrap the trigger in a setTimeout? 1412252872006157
_comment1: disregard what I wrote before...1412254667020152

disregard this comment

Changed October 21, 2014 12:31AM UTC by m_gol comment:16

resolution: → migrated
status: openclosed