summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--js/jquery.multi-select.js14
1 files changed, 12 insertions, 2 deletions
diff --git a/js/jquery.multi-select.js b/js/jquery.multi-select.js
index fb478f5..c653dd3 100644
--- a/js/jquery.multi-select.js
+++ b/js/jquery.multi-select.js
@@ -181,8 +181,18 @@
if (option.value !== undefined && option.value !== null &&
that.$element.find("option[value='"+option.value+"']").length === 0){
var $option = $('<option value="'+option.value+'">'+option.text+'</option>'),
- index = parseInt((typeof option.index === 'undefined' ? that.$element.children().length : option.index)),
- $container = option.nested === undefined ? that.$element : $("optgroup[label='"+option.nested+"']");
+ $container = option.nested === undefined ? that.$element : $("optgroup[label='"+option.nested+"']"),
+ index;
+
+ if(typeof option.index === 'undefined'){
+ if(typeof option.nested !== 'undefined' && option.nested !== null){
+ index = that.$element.children('[label="' + option.nested + '"]').children().length;
+ } else {
+ index = that.$element.children().length;
+ }
+ } else {
+ index = parseInt(option.index);
+ }
$option.insertAt(index, $container);
that.generateLisFromOption($option.get(0), index, option.nested);