Autocomplete for the chosen element from autocomplete

Hi,

How could I achieve the following - I have autocomplete which is working
pretty well, but after select any value from the list, I would like to
get in the search box another list of values associated with already
chosen value from the first list and to have autocomplete for the new
list of values? Actually, something like Google suggest functionality
(no, I am not going to launch Google suggest competition smile ), but I
would like to learn and eventually to implement something similar
locally for my web site.
For instance, if I have autocomplete list with dog races and choose
‘terrier’ from the list, I would like to get a new list with - let say
people who have terriers or something like this.

Are there any articles/howto’s which could give the right
comprehending/directionß

Thanks

On Mar 15, 2007, at 1:07 AM, Any Dot wrote:

For instance, if I have autocomplete list with dog races and choose
‘terrier’ from the list, I would like to get a new list with - let say
people who have terriers or something like this.

There is a completion option called “:after_update_element”. You can
assign there a callback

function (e, v) { … }

and generate a second widget based on the value in its body.

– fxn

There is a completion option called “:after_update_element”. You can
assign there a callback

function (e, v) { … }

and generate a second widget based on the value in its body.

– fxn

Can anyone offer some sample code on how to do this. I am a perl guru
but when it comes to javascript I’m a weenie.

On Mar 24, 2007, at 9:34 PM, psyber wrote:

Can anyone offer some sample code on how to do this. I am a perl guru
but when it comes to javascript I’m a weenie.

Sure.

That parameter is a JavaScript function that receives two arguments.
You can just build an ad-hoc anonymous subroutine for it, the
following construction is the JavaScript analogous of sub { … } in
Perl:

this is a Ruby string that contains JavaScript to be passed

to the helper, off the top of my head, untested

after_update_element_js = <<-JS.gsub(/\s+/, ’ ‘)
function(e, v) {
new Ajax.Request(’/foo/bar’, {
parameters: {value: e.value}, /* e.value is the completion */
asynchronous: true,
evalScripts: true
});
}
JS

And then:

<%= some_auto_completion_helper …, :after_update_element =>
after_update_element_js %>

Behind /foo/bar there’s a RJS that updates the second widget from
params[:value].

– fxn