Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Free text input with autocomplete on special symbols

I am building a chat widget that allows people to talk to each other in a web app. Most of the chat is therefore just text, but I'd like to allow people to say

enter image description here

which should appear in the chat as (for example)

enter image description here

Where typing the @ symbol allows Joe to be autocompleted from a list of users and also rendered as some sort of HTML element that isn't just text.

A great example is the tags box when asking or editing a question on StackOverflow - you can type free text which autocompletes to one or more tags; I basically want the tags to activate with a particular symbol (@ in this case) and still allow the free text otherwise. Another example is the comment reply field in StackOverflow where you can type @fooUser this is my response to your comment and fooUser becomes a link.

GitHub also does this; it provides different autocompletes for # (issue) and @ (user), i.e.:

enter image description here

enter image description here

I'm aware of libraries such as Twitter/Bootstrap typeahead and jQuery UI autocomplete, but they seem to autocomplete an entire input and are not flexible enough for doing things like this. There are two main issues here:

  • What's a good way to approach the hybrid rendering of both text and arbitrary DOM elements over an input field?
  • Is there an autocomplete library that supports in-line autocompletion, not just on the entire input?

I'm also fine with not rendering DOM elements in the text input/text area, but I can't find any libraries that do this type of hybrid free-text/autocomplete at all.

As an aside, I'm doing this in Meteor and so the data source for the autocomplete will be a Meteor collection. While that shouldn't affect how the data is hooked up too much, a Meteor-aware answer would be even more helpful.

Related to Twitter-style autocomplete in textarea but that question is over 2 years old with no good answers and hopefully something better has come along by now.

like image 945
Andrew Mao Avatar asked Sep 19 '13 16:09

Andrew Mao


People also ask

How do you autocomplete text?

Right-click the text box for which you want to enable or disable the AutoComplete feature, and then click Text Box Properties on the shortcut menu. Click the Display tab. Do one of the following: To enable AutoComplete for the text box, select the Enable AutoComplete check box.

How do you add suggestions to the input field?

Approach: Create a div with the class as a container. Inside of this div, create another div with a class as a text-container that will contain the <input> tag & <datalist> tag. Declare the list attribute as programmingLanguages inside the <input> tag.

Which attribute provides autocomplete feature for textfield?

The HTML | <input>autocomplete Attribute is used to specify whether the input field has autocompleted would be on or off. When the autocomplete attribute is set to on the browser will automatically complete the values based on which the user entered before.


1 Answers

Nothing too promising turned up in an extensive canvassing of libraries, but I thought I'd write things down for reference.

I'm excluding all full-field autocompletion libraries such as Typeahead and jQuery-autocomplete since they're not really what I'm looking for.

  • https://github.com/tactivos/jquery-sew (only supports one trigger)
  • https://github.com/Hawkers/triggeredAutocomplete (also only one trigger)
  • https://github.com/podio/jquery-mentions-input (one trigger, and unmaintained)
  • http://imankulov.github.io/asuggest/ (not very complete)

At this point, I'm fairly certain there's no industrial-strength library unless GitHub decides to open-source their code :). Fingers crossed...

like image 78
Andrew Mao Avatar answered Sep 25 '22 10:09

Andrew Mao