Forum: Ruby on Rails piggybacking an action on an autocompleted field

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Alain R. (Guest)
on 2006-04-02 01:51
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") %>
Alain R. (Guest)
on 2006-04-02 14:22
(Received via mailing list)
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]
This topic is locked and can not be replied to.