3

I am mostly a backend developer. And very new to javascript. So pardon my dumb question, but is there a way to trigger autocomplete when the user types '@' in a textfield. Like how it does in twitter.

Jonathan
  • 2,728
  • 10
  • 43
  • 73

4 Answers4

3

Take a look at onkeyup if you are using straight javascript. If you are using jQuery, try keyup.

From there, you can check to see if the user entered '@' and then make your auto-complete .

nutsch
  • 5,922
  • 2
  • 20
  • 35
MKS
  • 352
  • 3
  • 8
  • I wish I could mark both as correct. The other post was posted earlier thats why I marked it correct. Thank you so much for your answer though :) – Jonathan Oct 12 '12 at 19:07
2

Got two answers for you:

  1. I think this blog post has what you need: Triggered @mention Autocomplete like Facebook, Twitter and Google+
    Github repo: https://github.com/Hawkers/triggeredAutocomplete

  2. Also a similar question: Twitter-style autocomplete in textarea

Community
  • 1
  • 1
zengr
  • 38,346
  • 37
  • 130
  • 192
2

You could easily do it with http://complete-ly.appspot.com

just override the function onTextChange like this:

function onTextChange(text) {

   if (text.lastIndexOf('@') == text.length-1) { // ends with...

       // set the options, possibly change the text...
   }
}
special guest
  • 189
  • 1
  • 2
0

I've created a Meteor package for this purpose. Meteor's data model allows for fast multi-rule searching with custom rendered lists. If you're not using Meteor for your web app, (I believe) you unfortunately won't find anything this awesome for autocompletion.

Autocompleting users with @, where online users are shown in green:

enter image description here

In the same line, autocompleting something else using ! with metadata and bootstrap icons:

enter image description here

Fork, pull, and improve:

https://github.com/mizzao/meteor-autocomplete

Andrew Mao
  • 35,740
  • 23
  • 143
  • 224