Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Fix: typeahead data storing in list items #3698

Closed
wants to merge 1 commit into
from
Jump to file or symbol
Failed to load files and symbols.
+41 −3
Split
@@ -44,7 +44,7 @@
constructor: Typeahead
, select: function () {
- var val = this.$menu.find('.active').attr('data-value')
+ var val = this.$menu.find('.active').data('value')
this.$element
.val(this.updater(val))
.change()
@@ -136,7 +136,7 @@
var that = this
items = $(items).map(function (i, item) {
- i = $(that.options.item).attr('data-value', item)
+ i = $(that.options.item).data('value', item)
i.find('a').html(that.highlighter(item))
return i[0]
})
@@ -163,7 +163,45 @@ $(function () {
test("should set input value to selected item", function () {
var $input = $('<input />').typeahead({
- source: ['aa', 'ab', 'ac']
+ source: [
+ {
+ text: 'aa',
+ toLowerCase: function() {
+ return this.text
+ },
+ indexOf : function(str) {
+ return this.text.indexOf(str)
+ },
+ replace : function(pattern, replacement) {
+ return this.text.indexOf(pattern, replacement)
+ }
+ },
+ {text: 'ab',
+ toLowerCase: function() {
+ return this.text
+ },
+ indexOf : function(str) {
+ return this.text.indexOf(str)
+ },
+ replace : function(pattern, replacement) {
+ return this.text.indexOf(pattern, replacement)
+ }
+ },
+ {text: 'ac'
+ ,toLowerCase: function() {
+ return this.text
+ },
+ indexOf : function(str) {
+ return this.text.indexOf(str)
+ },
+ replace : function(pattern, replacement) {
+ return this.text.indexOf(pattern, replacement)
+ }
+ }
+ ],
+ updater: function (item) {
+ return item.text
+ }
})
, typeahead = $input.data('typeahead')
, changed = false