views:

40

answers:

2

Hi,

I have a textarea in which I write notes. When I enter a certain character, for example "@" I want to create an inline Jquery autocomplete which searches for a term matching the characters after the "@".

An example of the textarea input might be:

Please call @John Citizen regarding his order.

Any ideas?

A: 

Could this help you out?

tandu
Sorry, I should of mentioned that I've used Jquery autocomplete before, however this implementation is more advanced than I'm able.
matt
A: 

Well, it's not certainly not that simple, but here's how I would approach this problem.

First of all, take a very good look at the jQuery UI autocomplete plugin's documentations page. The solution here would be a combination of those.

You'll want to store the last character entered by the user in a variable, then check on autocompletesearch to see if the characters the user is currently entering is after an @ and before another whitespace character, and canceling the search by returning false if the condition is not met.

Next the source for the autocomplete will need to be a custom callback that processes the current content of the textarea for what the user has already typed after the @ and search through your array for matches to that name.

Finally, the autocompleteselect event will need to be modified to insert in the names in the correct positions after the user has chosen the name. The autocompletefocus event will also have to be suppressed for this to work. You'll want to have a look at the Multiple Tags and the combobox examples for this.

Yi Jiang