Bug Tracker

Opened 10 years ago

Closed 10 years ago

#13321 closed bug (invalid)

Clone() not cloning

Reported by: mail@… Owned by: mail@…
Priority: undecided Milestone: None
Component: unfiled Version: 1.9.0
Keywords: Cc:
Blocked by: Blocking:


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;

Change History (2)

comment:1 Changed 10 years ago by Rick Waldron

Owner: set to mail@…
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/

comment:2 Changed 10 years ago by trac-o-bot

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!

Note: See TracTickets for help on using tickets.