Skip to content

:selected bug #1

@bchavez

Description

@bchavez

Hi,

There seems to be an issue with the code:

/*
* Create the single select element by cloning the original multiple select.
/
$selectSingle = $(select).clone();
$selectSingle.removeAttr('id').removeAttr('name')
.addClass(options.classPrefix + '-select').insertAfter($(select));
/
Remove all the options inside the original select, and make it hidden */
$(select).empty().hide();

/* Get the list element from options or create a new one */
($list = $(options.list || $("<ul/>").insertAfter($selectSingle)))
    .addClass(options.classPrefix + '-list');

/* Add pre-selected options to the list */
$selectSingle.find(':selected').each(function () {
    add($(this), null, false);
});

If the HTML does not have a hard-coded "selected='selected'" attribute on the options (for example, the $(select).val() was set programatically), the select values are lost when preforming a $(select).clone(). Therefore, none of the "pre-selected" options are added to the list.

http://bugs.jquery.com/ticket/1294

http://stackoverflow.com/questions/1357410/whats-lost-during-clone-in-jquery

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions