Side navigation
#2941 closed bug (wontfix)
Opened May 27, 2008 02:36AM UTC
Closed March 17, 2009 10:54PM UTC
Last modified March 14, 2012 05:34PM UTC
<select> value and selected option not preserved on clone
Reported by: | fligtar | Owned by: | flesler |
---|---|---|---|
Priority: | major | Milestone: | 1.3 |
Component: | core | Version: | 1.2.5 |
Keywords: | clone select option | Cc: | |
Blocked by: | Blocking: |
Description
See test case here: http://fligtar.com/testcases/jquery-clone.html
When cloning a table row with a select box and a checkbox, the checkbox's value will be preserved, but the select box's value will not.
I was able to reproduce this in Firefox 3 and Safari.
Attachments (0)
Change History (5)
Changed May 27, 2008 01:27PM UTC by comment:1
need: | Review → Patch |
---|---|
owner: | → flesler |
status: | new → assigned |
Changed January 18, 2009 12:14AM UTC by comment:2
keywords: | testcase → testcase clone |
---|
Changed February 19, 2009 11:49PM UTC by comment:3
keywords: | testcase clone → clone select option |
---|
See also #4193.
Changed March 17, 2009 10:54PM UTC by comment:4
resolution: | → wontfix |
---|---|
status: | assigned → closed |
This was at one time in core but was removed due to the large performance overhead for such an edge case. I'm not convinced that the values should be cloned with the form elements. To really make it work cross browser you'd have to change the name attributes and ids as well. I remember having issues with radio buttons in Opera where even though it was in a different form only one could be checked. Either the original or the clone.
See also #3716
Changed March 31, 2010 05:34PM UTC by comment:5
First, welcome to Spamalot!
Someone delete the pseudo-medicine trash from harmony and maddie please.
Secondly, if you're a genius like me, and performance isn't an issue in a specific case then you can do something like this [excerpt]:
var erg=jQuery("td.add_row",row.parent().parent());
var elf=jQuery("<tr/>");
jQuery.each
(
erg,
function(i,item)
{
var flippingheck=jQuery(item).clone().appendTo(elf);
var bloodyhell=jQuery("select",jQuery(item));
var buggerme=jQuery("select",flippingheck);
jQuery.each
(
bloodyhell,
function(i,spy)
{
jQuery(buggerme[i]).attr("selectedIndex",jQuery(spy).attr("selectedIndex"));
}
);
}
);
// Other stuff after here
I think this is expected, the browser respects the selected and checked attributes. (Both are resetted on IE).
Maybe copying the value (or selectedIndex) attribute will be enough. Will check this when I get some time.
Thanks for the straight test case, much appreciated.