I have a textbox with an autocomplete tied to it. I'm also adding a custom element to the autocomplete dropdown when the text of the input box contains certain char. I'm adding this custom element customizing the _renderItem function of the plugin:
$tb.autocomplete({
/* OPTIONS HERE */
}).data("autocomplete")._renderItem = function (ul, item) {
if ($tb.val().indexOf('someText') > -1){
ul.append('<li class="dropdown-element"><a href="#" class="my-option">My custom option</a></li>');
}
return false;
}
I want that whenever the user types something that contains 'someText' and presses Enter (without selecting anything on the dropdown before), the 'select' event of the autocomplete is raised for my custom element.
I tried just adding a handler for the 'keyup' event on the textbox but the handler is called every time I press enter (even if there was some element selected in the dropdown) and I cannot cancel the propagation of the event from the 'select' event handler of the autocomplete. (I tried e.stopPropagation and e.originalEvent.stopPropagation but it still gets handled by the 'keyup' handler).
Any ideas on how to achieve this? Thanks