summaryrefslogtreecommitdiffstats
path: root/js/jquery.multi-select.js
diff options
context:
space:
mode:
authorIan <solidmoose@gmail.com>2016-09-18 03:49:07 -0700
committerIan <solidmoose@gmail.com>2016-09-18 03:49:07 -0700
commitb5e268a27c8c0a1da068bb5dbaa18ee6aa92c577 (patch)
tree50cb5480b0bf54ea63446ad650d44517477b1399 /js/jquery.multi-select.js
parenta0f48de085568a5040e7edef29999e4b17a700a1 (diff)
downloadmulti-select-b5e268a27c8c0a1da068bb5dbaa18ee6aa92c577.zip
multi-select-b5e268a27c8c0a1da068bb5dbaa18ee6aa92c577.tar.gz
multi-select-b5e268a27c8c0a1da068bb5dbaa18ee6aa92c577.tar.bz2
Fix addOption when 'nested' specified
Diffstat (limited to 'js/jquery.multi-select.js')
-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);