Piggybacking an action on an autocompleted field


#1

Hi everybody,

I’d like to add a custom action to be triggered after/when an
autocompleted field has been/is beeing updated by the autocompletion
process.
I tried the obvious - a field observer -, but it doesn’t work (see code
below). I know I could write the autocompletion code myself, but I
wonder if there is a simpler/more elegant way?

Any idea?
TIA

Alain

The observer solution (that doesn’t work):

<%= text_field_with_auto_complete :city, :zip    %>
<%= observe_field("city_zip",
   :frequency => 0,
   :url => { :action => :get_names_for_zip },  <<<---- IS NEVER 

CALLED
:with => “‘zip=’+value”) %>


#2

There’s already a tiny patch - 3691 - in the waiting list that solves
that very problem, and lets you write
<%= text_field_with_auto_complete :city, :zip ,{},
:after_update_element=> “alert(‘after_update_element…’)”
%>

Alain

http://dev.rubyonrails.org/ticket/3691
[PATCH] Add frequency and afterupdateelement option to

text_field_with_auto_complete

It justs adds 2 lines in the auto_complete_field method
(java_script_macros_helper.rb)
js_options[:frequency] = “#{options[:frequency]}” if
options[:frequency]
js_options[:afterUpdateElement] = “function(element,value) {
return #{options[:after_update_element]}(element,value); }” if
options[:after_update_element]