When typing in a text control it would be nice to have auto-complete based on some predefined values.
In my example we have a list of names setup against a handle like @johnsmith.
If typing in the textbox when a person types a @name it would check against the available names and validate, if invalid they would be presented a list to pick the correct name (like how spell check works)
This was brought up in a support ticket, notes below:
Do have the following in mind:
* implementing the simplest case e.g. @mentions will simply not do. there are tons of other completes that can be done e.g. #hashes, :emoji and so on
* developers will need to verify that tokens are indeed valid and what to do with invalid tokens e.g. if I type @nosuchuser and there isn't such user, should the token be left literal or should it be processed like the rest?
* there should be a way to specify the data source location for those completes...
But the most important part was the emphasis on the token validation and data source.
Apart from that the logic is fairly simple: a textbox with events for keypress. As soon as a trigger key is pressed the autocomplete part pops and the user either selects a value from a list or types one. The "rich" value is saved in a hidden field. If the value happens to be a valid one, it has special formatting (because at the end we are submitting the rich value).