How to make the Auto Clomplete open the bottom of the line where it is being typed?

Asked

Viewed 42 times

0

I have an auto complete system and I wanted the Aseemcem options goes down from the line where the user is typing, as for example code editors like the Dreamweaver.

Auto Complete - Jquery:

$(function() {
var availableTags = [
  "<a></a>",
  "<sub></sub>"
];
function split( val ) {
  return val.split( /\s*/ );
}
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 &&
        $( this ).autocomplete( "instance" ).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.value );
      // remove the current input
      terms.pop();
      // add the selected item
      terms.push( ui.item.value );
      // add placeholder to get the comma-and-space at the end
      terms.push( "" );
      this.value = terms.join( "" );
      return false;
    }
  });

});

HTML:

<textarea id="tags" ></textarea>

1 answer

0

You can use the autofocus attribute for this. When you find the word just click enter. See the example:

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>jQuery UI Autocomplete - Default functionality</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script>
  $(function() {
    var availableTags = [
      "ActionScript",
      "AppleScript",
      "Asp",
      "BASIC",
      "C",
      "C++",
      "Clojure",
      "COBOL",
      "ColdFusion",
      "Erlang",
      "Fortran",
      "Groovy",
      "Haskell",
      "Java",
      "JavaScript",
      "Lisp",
      "Perl",
      "PHP",
      "Python",
      "Ruby",
      "Scala",
      "Scheme"
    ];
    $( "#tags" ).autocomplete({
      source: availableTags,
      autoFocus: true
    });
  });
  </script>
</head>
<body>
 
<div class="ui-widget">
  <label for="tags">Tags: </label>
  <textarea id="tags"></textarea>
</div>
 
 
</body>
</html>

EDIT 1:

Take a look at this plugin: http://yuku-t.com/jquery-textcomplete/

  • that’s not what I wanted, I wanted these tags to look like in the line below which typed, in case he is typing in line 1, in line 2 would appear the tags for him to celerize.

  • I don’t understand, can you put an image attached to your question?

  • ok, http://i.stack.Imgur.com/Rannh.jpg, like this I wanted to

  • The effect you want is the same one I posted. Search for example by java and press Enter the effect will be the same

  • Note that it is not simple autocomplete, it has the focus feature on the first item in the list

  • I’m sorry I’m late because I forgot this question :-/. Not what I wanted was just the position as an example, I have a textarea with the height of 1500px and wanted the auto complete appears below the line in which this typing as in the photo. I hope I made it clear, sorry for the delay

  • See EDIT 1 pf

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.