[jQuery] Select Box Manipulation plugin - odd behavior?
Is anyone familiar with the Select Box Manipulation plugin?
I'm seeing some 'odd' behavior and I wonder if anyone else has seen
it.
Basically, if I sort a select then use addOption to give new text to
an existing option the wrong option gets the new text. (I have a link
that I could share that shows the issue).
One thing that is part of my issue is that I want to keep a certain
option at the top of the list. To do that I am giving it new text
before the sort (something like 'AAA'), sorting the list, then putting
back the text that is more helpful to the user.
After this I am calling addOption to rename selected options. If I
select option 2 in the list, for example, and call addOption, it
renames option 5 in the list of select options. Some options rename
themsleves, others rename other options.
There are just 2 simple functions needed to see my issue:
function SortAndMaintainMessage () {
// rename the message option
$("#TheSelect").addOption("TheMessageOption", "AAA");
// sort the select options
$("#TheSelect").sortOptions();
// put back the text of the message option
$("#TheSelect").addOption("TheMessageOption", "Select an option");
return false;
}
function RetextSelectedOption () {
var selectedOptionsText = $('#TheSelect option:selected').text();
var selectedOptionsValue = $('#TheSelect option:selected').val();
if (!selectedOptionsValue) {
alert('seems there is no option selected: ' +
selectedOptionsValue );
return false;
} else {
$("#TheSelect").addOption(selectedOptionsValue, "New text for this
option");
return false;
}
}
I can make calls to the RetextSelectedOption() function and it works
fine but once I make a call to SortAndMaintainMessage() the
RetextSelectedOption() function no longer changes the text of the
selected option.
Any help is appreciated...