From cf7ac2a574ef05186883b6e062d1d9190ee189b3 Mon Sep 17 00:00:00 2001 From: Stefan Morgenthaler Date: Thu, 18 Sep 2014 11:58:51 +0200 Subject: [PATCH 1/3] add new method removeOption --- js/jquery.multi-select.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/js/jquery.multi-select.js b/js/jquery.multi-select.js index c99cc5a..f0fe26b 100644 --- a/js/jquery.multi-select.js +++ b/js/jquery.multi-select.js @@ -187,6 +187,18 @@ }) }, + 'removeOption' : function(options){ + var that = this; + + if (options.value) options = [options]; + $.each(options, function(index, option){ + if (option.value && that.$element.find("option[value='"+option.value+"']").length === 1){ + that.$element.find("option[value='" + option.value + "']").remove(); + that.$container.find("ul.ms-list [id^='" + option.value + "']").remove(); + } + }) + }, + 'escapeHTML' : function(text){ return $("
").text(text).html(); }, From 69f00988ab354ab2e273ba84b28061029219c908 Mon Sep 17 00:00:00 2001 From: Stefan Morgenthaler Date: Thu, 18 Sep 2014 11:59:26 +0200 Subject: [PATCH 2/3] add tests for removeOption and addOption --- test/spec/multiSelectSpec.js | 37 ++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/test/spec/multiSelectSpec.js b/test/spec/multiSelectSpec.js index c27226e..d379852 100644 --- a/test/spec/multiSelectSpec.js +++ b/test/spec/multiSelectSpec.js @@ -389,4 +389,41 @@ describe("multiSelect", function() { }); }); }); + + describe('manipulation of values', function(){ + + describe('when calling the "addOption" method', function(){ + beforeEach(function(){ + select.multiSelect(); + select.multiSelect('addOption', { value: 'test', text: 'test' }); + }); + + it('should add a new option to the original select', function() { + expect( select.children('option').length ).toEqual(11); + }); + + it('should add a new li entry to the multiselect container', function() { + expect( $("div.ms-container .ms-selectable li").length ).toEqual(11); + expect( $("div.ms-container .ms-selection li").length ).toEqual(11); + }); + }); + + describe('when calling the "removeOption" method', function(){ + + beforeEach(function(){ + select.multiSelect(); + select.multiSelect('removeOption', {value: 'value1' }); + }); + + it('should remove the specified option from the original select', function() { + expect( select.children('option').length ).toEqual(9); + }); + + it('should remove the specified li entry from the multiselect container', function() { + expect( $("div.ms-container li[id^='value1-']").length ).toEqual(0); + }); + }); + + }); + }); From 8aad90f8911b094e564900d10d61d41c47ce055b Mon Sep 17 00:00:00 2001 From: Stefan Morgenthaler Date: Thu, 18 Sep 2014 12:17:00 +0200 Subject: [PATCH 3/3] documentation update for loudev.com (patch) --- documentaion_at_loudev.com.html.patch | 36 +++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 documentaion_at_loudev.com.html.patch diff --git a/documentaion_at_loudev.com.html.patch b/documentaion_at_loudev.com.html.patch new file mode 100644 index 0000000..1e224b0 --- /dev/null +++ b/documentaion_at_loudev.com.html.patch @@ -0,0 +1,36 @@ +--- index.html 2014-09-18 12:01:30.776022500 +0200 ++++ index_new.html 2014-09-18 12:10:26.224562000 +0200 +@@ -305,7 +305,32 @@ + +

+
$('#your-select').multiSelect('addOption', { value: 'test', text: 'test', index: 0, nested: 'optgroup_label' });
+-
++

.multiSelect('removeOption', Hash)

++

++ Dynamically remove option from the multiselect. ++
++ The options hash is described bellow: ++

++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++
keytyperequireddesription
valueStringtrueThe value of the option to remove
++

++
$('#your-select').multiSelect('removeOption', { value: 'test' });
++
+

Keyboard

+ +