Autocomplete for the chosen element from autocomplete

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

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