Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

:selected bug #1

Open
bchavez opened this issue Mar 1, 2011 · 1 comment
Open

:selected bug #1

bchavez opened this issue Mar 1, 2011 · 1 comment

Comments

@bchavez
Copy link

bchavez commented Mar 1, 2011

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

@bchavez
Copy link
Author

bchavez commented Mar 1, 2011

This copying the values before cloning actually works:

var values = $(select).val();
$selectSingle = $(select).clone();
$selectSingle.val(values); //set values back on clone: jquery bug behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant