I've found a rather tricky bug in jQuery 1.0.2. When you use an animated slideDown() or show() on an element containing one or more radio buttons, the radio buttons lose their selection status in Firefox (1.5 and 2.0 for sure, maybe others), and Opera 9 (maybe others). It works fine in IE6 and Safari 2. This also only seems to happen when you apply an animation for the first time.

I have attached a minimal test case to reproduce. There are four pairs of radiobuttons, each having one radio button selected. Their source markup is functionally identical. Clicking the provided link runs a different animation on each radio button pair: the first two pairs of radio buttons lose their selection, the last two work fine.

This is caused by the code in jQuery.css() used to measure the dimensions of elements that are hidden. jQuery temporarily replicates the element inside its parent. This causes two selected radio buttons with the same 'name' to appear in the form, which is not allowed. It seems that Firefox and Opera defensively remove both selections in this case.

One fix is to simply remove the checked attributes of all radio buttons inside the clone, before inserting it into the parent. See attached patch.

This is a major blocker for jQuery in Drupal by the way, as it can break any animated portion of a form. I'm going to patch our included copy after you guys review this patch (we have a release candidate coming up next monday), but it would be nice to see this fixed in a 1.0.3 release soon ;).

Steven Wittens

Attachment: jquery-radio-bug.patch
Description: Binary data


Title: jQuery Radio bug

Problem: when using some animations on an element containing one or more radio buttons, the radiobuttons will lose their selection in Firefox and Opera, the first time the animation is applied.

Click to trigger bug

slideDown: Buggy

animated show: Buggy

fadeIn: Not Buggy

instant show: Not Buggy

_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to