Side navigation
#3879 closed bug (fixed)
Opened January 15, 2009 08:09PM UTC
Closed January 10, 2011 12:41AM UTC
appending or cloning a checked checkbox or radio button doesn't maintain the default state
Reported by: | Pyro979 | Owned by: | snover |
---|---|---|---|
Priority: | blocker | Milestone: | 1.5 |
Component: | manipulation | Version: | 1.4.4 |
Keywords: | append checked selected defaultValue defaultSelected defaultChecked | Cc: | |
Blocked by: | Blocking: |
Description
This looks like a similar bug to #769, but I am experiencing this in IE7.
var check=$(document.createElement("input")).attr("type","checkbox");
check.attr("checked",true);
$("#id_main1").append(check);
The appended checkbox is no longer checked. There is an obvious workaround I can (and did) write meanwhile. But this is a pretty serious bug in my opinion.
Attachments (1)
Change History (33)
Changed January 15, 2009 09:47PM UTC by comment:1
Changed January 16, 2009 12:16AM UTC by comment:2
Updated the test case, bug still applies.
Changed January 17, 2009 10:36PM UTC by comment:3
milestone: | → 1.3.1 |
---|---|
owner: | → john |
Is this a bug that's new in jQuery 1.3 or did it also exist in jQuery 1.2.6?
Changed January 18, 2009 07:20PM UTC by comment:4
It exists in 1.2.6 as well.
Changed January 31, 2009 03:58AM UTC by comment:5
This is an old bug with IE6/7 appendChild, it clears the checked state of a checkbox. I thought there was a ticket related to the same issue with
.clone()but I can't find it.
Changed January 06, 2010 12:20AM UTC by comment:6
See also #5758, which shows a similar problem with radios.
Changed March 01, 2010 11:09PM UTC by comment:7
We're running in to this issue as well. Anyone know the status of fixing this? In the interim, we can set the checked state as part of the HTML construction, i.e. $('<input type="checkbox" checked="checked"/>') as a workaround.
While @Wildman may be correct re the spec, even IE6 supports using boolean flags with the .attr(...) function. That is to say, once the checkbox is added to the DOM, <obj>.attr('checked', true) works as expected. However, as noted in the bug, prior to adding to the DOM, the attr(...) function does not work - even when chained at the end of the append() function.
Changed June 16, 2010 03:13AM UTC by comment:9
component: | core → manipulation |
---|
Changed November 03, 2010 10:00PM UTC by comment:10
Created a jsfiddle testcase http://jsfiddle.net/boushley/R3Wxx/ is running against 1.3.2 and http://jsfiddle.net/boushley/R3Wxx/1/ is running against 0 GIT. I can reproduce it from IE 7.
Changed November 04, 2010 10:53PM UTC by comment:11
status: | new → open |
---|
Tested and passing in:
- FF3.0.12,3.6.11,4b6
- Chrome 5,6,7,8
- Safari 5
- IE 6,7,8
- Opera 10.60
Changed November 04, 2010 11:17PM UTC by comment:12
resolution: | → worksforme |
---|---|
status: | open → closed |
Per addyosmani request, a third method:
Changed November 04, 2010 11:37PM UTC by comment:13
Per snover request
Changed November 04, 2010 11:43PM UTC by comment:14
milestone: | 1.3.1 |
---|---|
resolution: | worksforme |
status: | closed → reopened |
Changed November 04, 2010 11:44PM UTC by comment:15
resolution: | → wontfix |
---|---|
status: | reopened → closed |
To clarify, my cases are meant to show proven, tested workaround to this unfixable, unsolvable problem.
Changed November 04, 2010 11:45PM UTC by comment:16
resolution: | wontfix |
---|---|
status: | closed → reopened |
Changed November 19, 2010 03:56AM UTC by comment:17
#5758 is a duplicate of this ticket.
Changed November 19, 2010 03:57AM UTC by comment:18
summary: | appending a checked checkbox doesn't maintain the cheked state → appending a checked checkbox or radio button doesn't maintain the checked state |
---|
Changed November 19, 2010 08:11AM UTC by comment:19
#6486 is a duplicate of this ticket.
Changed November 20, 2010 09:34PM UTC by comment:20
#3704 is a duplicate of this ticket.
Changed November 20, 2010 09:35PM UTC by comment:21
keywords: | append checkbox → append checked selected defaultValue defaultSelected defaultChecked |
---|---|
summary: | appending a checked checkbox or radio button doesn't maintain the checked state → appending or cloning a checked checkbox or radio button doesn't maintain the default state |
Changed November 21, 2010 10:48PM UTC by comment:22
I can confirm that this is still an issue in 1.4.2, and assuming that it's still open, in 1.4.3+.
The workaround suggested by icfantv still works.
Changed November 22, 2010 05:52AM UTC by comment:23
priority: | major → low |
---|---|
resolution: | → patchwelcome |
status: | reopened → closed |
version: | 1.3 → 1.4.4 |
I don’t know if there is really anything that can be done about this in a way that is satisfactory; if someone wants to try their hand at a patch, we would be happy to review it.
Changed November 30, 2010 04:34AM UTC by comment:24
I wish this ticket weren't closed. I've actually noticed the exact same issue in Chrome.
Changed November 30, 2010 03:00PM UTC by comment:25
Replying to [comment:24 julien]:
I wish this ticket weren't closed. I've actually noticed the exact same issue in Chrome.
As snover mentioned, patches are welcome.
Changed December 07, 2010 09:37PM UTC by comment:26
Didn't see a test case using clone: http://www.jsfiddle.net/fletch/CLq3P/
Works fine in Firefox 3.6 and Chrome 8, does not work in IE8.
Changed December 30, 2010 05:46AM UTC by comment:27
milestone: | → 1.5 |
---|---|
resolution: | patchwelcome |
status: | closed → reopened |
Changed December 30, 2010 05:46AM UTC by comment:28
owner: | john → snover |
---|---|
status: | reopened → assigned |
Changed January 07, 2011 08:25PM UTC by comment:29
Let me say right away that I'm not sure that I'm doing this correctly, and whether or not this is the "proper" way to fix this bug. But this seems to work. I can probably benefit from some more optimization
Changed January 08, 2011 10:26PM UTC by comment:30
Just added a jQuery.support.checkboxAppendPermanence check into support.js. This should improve performance since we won't need to do any of this "checked" re-assigning when it works fine. Don't know if I put it into the right spot.
Changed January 08, 2011 10:29PM UTC by comment:31
Pyro979, there is already an outstanding open pull request for this issue; you don’t need to write code to fix this ticket.
Changed January 08, 2011 10:29PM UTC by comment:32
priority: | low → blocker |
---|
Changed January 10, 2011 12:41AM UTC by comment:33
resolution: | → fixed |
---|---|
status: | assigned → closed |
Ensure that buildFragment clones elements properly in all browsers. Fixes #3879, #6655. Also improves form element clone tests and fixes bugs in $.fn.clone exposed by these new test cases related to the values of checkboxes and radio buttons in IE.
Changeset: b14f02899e74c429effadd88527ffde17650149a
check.attr("checked", true) should not work at all because it is check.attr("checked", "checked") see W3C XHTML