Scriptaculous: Autocompleter in textarea on character event


I have a usecase of calling an Autocompleter.Local when a special
character is typed in the textarea. The autocompleter will suggest a
drop down matching the characters that user typed after the special
character and lets the user pick from the list to fill it.

Here is what I have done,

When the user clicks in the textarea, I fetched an array of elements by
sending an ajax request to the controller function which renders a jason
object array. I collected the response from the callback function of my
ajax reqest and evaluated the jason object and stored the elements in a
javascript global array. Well this serves my purpose of fetching the
array on request only and to be able to pass to the Autocompleter.Local
function of scriptaculous with the “token” as my special character(say

Now, here comes the story. When I try to call the Autocompleter.Local
typing the “@” an autocompleter dropdown pops and let me choose using
the mouseclick. But when I try to select using the navigation keys
(KEY_RETURN or KEY_TAB) it doesnt work as expected.

Here is the exact problem. Let my array be
var my_array =

and the autocompleter call as,

function okKeyDownPollingFunction(event.value){
if (event.value == 50){ //char value for @
new Autocompleter.Local(‘textarea_id’, ‘div_id’, my_array, {tokens:

Now when I type “@R|” ("|" indicates cursor position)in the textarea the
dropdown pops and lets me select(say RForum2) using the RETURN KEY(or
TAB KEY)and fills as @RForum2 in the text area. When i type @R| (or @RF
or @RFo…) again and selected RForum1 it displays as
@RForum2 <something/nothing> @RForum1rum1” when cursor as in @RFo|
(pattern repeats once),
@RForum2 <something/nothing> @RForum1m1” when cursor as in @RForu|
(pattern repeats twice),
@RForum2 <something/nothing> @RForum1m1 <something/nothing>
@RForumorumorum” when cursor as in @RF|, (third time use of “@” pattern
repeats thrice)

Can some one help me out as this seems impossible for a young developer
like me. I tried to debug the controls.js, the scriptaculous source
file, but invain.

Any other alternative for the same usecase or fix/patch for
scriptaculous that would let me fix the problem is much appriciated.

Thanks in advance!

S M Sharief
[email protected]