Skip to content

Commit

Permalink
Prevent selection of first item in typeahead list
Browse files Browse the repository at this point in the history
  • Loading branch information
Rashid Khan committed Oct 12, 2013
1 parent c6b1503 commit 19dc44d
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/vendor/bootstrap/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -1906,7 +1906,8 @@
constructor: Typeahead

, select: function () {
var val = this.$menu.find('.active').attr('data-value')
// CHANGE (rashidkpc) If nothing is selected, use existing value
var val = this.$menu.find('.active').attr('data-value') || this.$element.val();
this.$element
.val(this.updater(val))
.change()
Expand Down Expand Up @@ -2005,7 +2006,8 @@
return i[0]
})

items.first().addClass('active')
// CHANGE (rashidpc) Do not select first element by default
// items.first().addClass('active')
this.$menu.html(items)
return this
}
Expand Down Expand Up @@ -2116,8 +2118,14 @@
this.lookup()
}

e.stopPropagation()
e.preventDefault()
if(e.keyCode === 13 && typeof this.$menu.find('.active').attr('data-value') === 'undefined') {
// CHANGE (rashidkpc). Enter was hit, nothing was selected from typeahead, submit form
this.$element.submit();
} else {
e.stopPropagation()
e.preventDefault()
}

}

, focus: function (e) {
Expand Down

0 comments on commit 19dc44d

Please sign in to comment.