javascript - Bootstrap 2.3.2 typeahead trigger ENTER keyCode event when an item is clicked -
i have text input field , i'm using bootstrap typeahead set state names typeahead values. have function foo
, takes event keycode input, , adds text field input value list (it's more complex that, details shouldn't important). user can input values field multiple times, , each time user inputs value , presses "enter", foo
called , input field cleared. i've noticed that, if type few letters, use arrow keys select value want, , press "enter", foo
gets called item , it's added list expected. however, when type few letters , use mouse click on value want, correct value gets put text field, foo
not called. if user presses "enter" @ point foo
called expected, want foo
called user clicks value in typeahead list.
i have tried 2 methods far.
1) add click
event handler input such:
$('input').on('click', function() { // call foo() passing enter event keycode })
this problematic because triggered whenever user clicks input box, wanted see if gets called user clicks on value in typeahead list. found not, seems bootstrap typeahead propagates keyup
event input box, not click
event. correct, or else happening here?
2) trigger event using updater
method of bootstrap typeahead:
$('input').typeahead({ source: statelist, updater: function(item) { // trigger 'keyup' event keycode 13 (the enter keycode) return item; } });
this shouldn't work, since item returned after event triggered. expect happen here whatever user has entered input field gets added list (e.g. if type "ca" , click on "california", "ca" added instead of "california"), seems isn't happening either, foo
still isn't getting called.
the bootstrap 2 documentation on typeaheads sparse, , unfortunately can't upgrade bootstrap 3 project. there way accomplish i'm trying bootstrap 2 typeahead?
tl;dr want input value entered in text box , submitted ("enter" key pressed) when click on value bootstrap typeahead list. works fine when "enter" used select list item, not when mouse used. how make bootstrap typeahead add , submit value when selected mouse click?
Comments
Post a Comment