Alain Ravet
2006-Apr-01 21:51 UTC
[Rails] piggybacking an action on an autocompleted field
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") %> -- Posted via http://www.ruby-forum.com/.
Alain Ravet
2006-Apr-02 10:20 UTC
[Rails] (SOLVED) Re: piggybacking an action on an autocompleted field
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]