Twitter bootstrap typeahead custom keypress ENTER function
I'm working with Twitter bootstrap on a Django site I'm making. I have a
page where users can enter all of their technical skills in a text input
equipped with a bootstrap typeahead. I'm trying to access the text within
the currently selected within the dropdown menu, such that when ENTER is
pressed and an element is highlighted in the dropdown, it takes that value
and displays it below the input text field. Then the input text field is
cleared and the user can search for another skill.
$(document).keyup(function(event) {
if (event.keyCode == 13) {
if ($('.dropdown-menu').css('display') != 'none'){
var newskill = $(".dropdown-menu > li.active").val();
alert('Yay');
}
else{
var newskill = $("#enterbox").val();
alert('Boo');
}
return false;
}
});
If the dropdown is visible, then the enter keypress function takes the
currently active element of the dropdown and pastes it into the text box
(built in to Bootstrap). No alert box shows. Any idea how I can get my
function to trigger before that happens, ie before Bootstrap's function
kicks in?
No comments:
Post a Comment