Note that there are some explanatory texts on larger screens.

plurals
  1. POjquery autocomplete stop focus on target element
    primarykey
    data
    text
    <p>I am using jquery autocomplete on a contenteditable div say myDiv. It is working fine. When I navigate autocomplete menu items and reaches to the top then press up key myDiv gets focus. If I press up key again the last item in the menu get focused. I want to stop focusing on the target when navigate menu items. Is there any way to do that ?</p> <h2>Update</h2> <p>I have create a fiddle <a href="http://jsfiddle.net/aj6Bv/1/" rel="nofollow">1</a></p> <h2>Steps</h2> <ol> <li>Add two items</li> <li>Type for another items</li> <li>navigate to the top items then press up key. You will see that div gets focus and my ui style lost.</li> </ol> <p><code></p> <pre><code>$(function() { var selectedLanguages = []; var availableTags = [ "ActionScript", "AppleScript", "Asp", "BASIC", "C", "C++", "Clojure", "COBOL", "ColdFusion", "Erlang", "Fortran", "Groovy", "Haskell", "Java", "JavaScript", "Lisp", "Perl", "PHP", "Python", "Ruby", "Scala", "Scheme" ]; function split( val ) { return val.split(/[\s|\u00A0]/); } function extractLast( term ) { return split( term ).pop(); } $( "#tags" ) // don't navigate away from the field on tab when selecting an item .bind( "keydown", function( event ) { if ( event.keyCode === $.ui.keyCode.TAB &amp;&amp; $( this ).data( "ui-autocomplete" ).menu.active ) { event.preventDefault(); } }) .autocomplete({ minLength: 0, source: function( request, response ) { // delegate back to autocomplete, but extract the last term response( $.ui.autocomplete.filter( availableTags, extractLast( request.term ) ) ); }, focus: function() { // prevent value inserted on focus return false; }, select: function( event, ui ) { var terms = split( this.innerHTML ); // remove the current input terms.pop(); // add the selected item selectedLanguages.push( ui.item.value ); terms.push(" "); //this.value = terms.join( ", " ); addTags(selectedLanguages); return false; } }); }); function addTags(tags){ $("#tags").html(""); var tagHtml = ""; for(var i in tags){ tagHtml+="&lt;span&gt;"+tags[i] +"&lt;/span&gt;&amp;nbsp;"; } $("#tags").html(tagHtml); } </code></pre> <p></code></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload