Skip to main content

Bug Tracker

Side navigation

#13321 closed bug (invalid)

Opened January 24, 2013 03:38PM UTC

Closed February 08, 2013 08:46AM UTC

Clone() not cloning

Reported by: mail@eliassorensen.dk Owned by: mail@eliassorensen.dk
Priority: undecided Milestone: None
Component: unfiled Version: 1.9.0
Keywords: Cc:
Blocked by: Blocking:
Description

When cloning a select, and one of the options has been selected, the selected option isn't selected when cloned.

Try making a select with 2+ options and select the second option, and then clone the select. In the new cloned select, the selected option is now the first (the select has been initialized).

Here is a fixed clone() function that remembers the selected option:

jQuery.fn.clone = function () {
    var result = original.apply(this, arguments),
        my_textareas = this.find('textarea').add(this.filter('textarea')),
        result_textareas = result.find('textarea').add(result.filter('textarea')),
        my_selects = this.find('select').add(this.filter('select')),
        result_selects = result.find('select').add(result.filter('select'));

    for (var i = 0, l = my_textareas.length; i < l; ++i) $(result_textareas[i]).val($(my_textareas[i]).val());
    for (var i = 0, l = my_selects.length; i < l; ++i) result_selects[i].selectedIndex = my_selects[i].selectedIndex;

    return result;
};
})(jQuery.fn.clone);
Attachments (0)
Change History (2)

Changed January 24, 2013 04:26PM UTC by rwaldron comment:1

owner: → mail@eliassorensen.dk
status: newpending

Thanks for taking the time to contribute to the jQuery project! Please provide a complete reduced test case on jsFiddle to help us assess your ticket!

Additionally, be sure to test against the "jQuery (edge)" version to ensure the issue still exists—you may need to change this to a specific version depending on the test case.

To get you started, use this boilerplate: http://jsfiddle.net/FrKyN/ Open the link and click to "Fork" (in the top menu) to begin.

Also, please read: http://blog.jquery.com/2013/01/15/jquery-1-9-final-jquery-2-0-beta-migrate-final-released/

Changed February 08, 2013 08:46AM UTC by trac-o-bot comment:2

resolution: → invalid
status: pendingclosed

Because we get so many tickets, we often need to return them to the initial reporter for more information. If that person does not reply within 14 days, the ticket will automatically be closed, and that has happened in this case. If you still are interested in pursuing this issue, feel free to add a comment with the requested information and we will be happy to reopen the ticket if it is still valid. Thanks!