Permalink
Browse files

Added fix for a bug that @rversaw pointed out.

after the user selected multiple items there would be extra spaces hanging around in the input field
  • Loading branch information...
codeimpossible committed Mar 1, 2012
1 parent 97283f2 commit 9bf32cd8050615ef630b8f84f4b356a3123e0403
Showing with 28 additions and 2 deletions.
  1. +1 −1 docs/assets/js/bootstrap-typeahead.js
  2. +1 −1 js/bootstrap-typeahead.js
  3. +26 −0 js/tests/unit/bootstrap-typeahead.js
@@ -75,7 +75,7 @@
var that = this
, items
, q
- , input = this.mode === 'multiple' ? this.$element.val().split(this.delimiter) : [this.$element.val()]
+ , input = this.mode === 'multiple' ? this.$element.val().split(this.formatteddelimiter()) : [this.$element.val()]
this.selections = input.slice(0, input.length - 1)
@@ -75,7 +75,7 @@
var that = this
, items
, q
- , input = this.mode === 'multiple' ? this.$element.val().split(this.delimiter) : [this.$element.val()]
+ , input = this.mode === 'multiple' ? this.$element.val().split(this.formatteddelimiter()) : [this.$element.val()]
this.selections = input.slice(0, input.length - 1)
@@ -230,4 +230,30 @@ $(function () {
equals($input.val(), 'ac, aa, ', 'input value was correctly set')
})
+
+ test("should not have extra spaces when multiple items are selected", function () {
+ var $input = $('<input />').typeahead({
+ source: ['aa', 'ab', 'ac']
+ , delimiter: ';'
+ , mode: 'multiple'
+ })
+ , typeahead = $input.data('typeahead')
+
+ $input.val('a')
+ typeahead.lookup()
+
+ $(typeahead.$menu.find('li')[2]).mouseover().click()
+
+ $input.val( $input.val() + 'a')
+ typeahead.lookup()
+
+ $(typeahead.$menu.find('li')[2]).mouseover().click()
+
+ $input.val( $input.val() + 'a')
+ typeahead.lookup()
+
+ $(typeahead.$menu.find('li')[2]).mouseover().click()
+
+ equals($input.val(), 'ac; ac; ac; ', 'input value was correctly set')
+ })
})

4 comments on commit 9bf32cd

@ccmcbeck

This comment has been minimized.

Show comment Hide comment
@ccmcbeck

ccmcbeck Oct 27, 2012

Do you have plans to apply this feature to Bootstrap 2.1.1?

Do you have plans to apply this feature to Bootstrap 2.1.1?

@codeimpossible

This comment has been minimized.

Show comment Hide comment
@codeimpossible

codeimpossible Oct 28, 2012

Owner

Definitely, not sure if I'll be able to get to around to that any time soon though.

Definitely, not sure if I'll be able to get to around to that any time soon though.

@ccmcbeck

This comment has been minimized.

Show comment Hide comment
@ccmcbeck

ccmcbeck Oct 31, 2012

Maybe I'll get off my a** and help. It's a great widget.

Maybe I'll get off my a** and help. It's a great widget.

@codeimpossible

This comment has been minimized.

Show comment Hide comment
@codeimpossible

codeimpossible Oct 31, 2012

Owner

that would be a huge help, and totally awesome :D

that would be a huge help, and totally awesome :D

Please sign in to comment.