I''ve been searching for a way to get DHH''s auto_complete plugin to work with Ryan Bates'' complex forms. All I could find was people asking the same question, but no solutions so I decided to try it myself. I don''t know if this id the best way to do it, but the solution was to monkey patch ActionView::FormHelper and FormBuilder which I put in a seperate file in the /lib folder of my project. Here''s the code: ## lib/auto_complete_form_helper.rb module ActionView module Helpers module FormHelper def text_field_with_auto_complete_mod(object, method, tag_options = {}, completion_options = {}) sanitized_object = object.gsub(/\]\[|[^-a-zA-Z0-9:.]/, "_").sub (/_$/, "") sanitized_method = method.to_s.sub(/\?$/,"") (completion_options[:skip_style] ? "" : auto_complete_stylesheet) + text_field(object, method, tag_options) + content_tag("div", "", :id => "#{sanitized_object}_# {sanitized_method}_auto_complete", :class => "auto_complete") + auto_complete_field("#{sanitized_object}_#{sanitized_method}", { :url => { :action => "auto_complete_for_#{sanitized_object}_# {sanitized_method}" } }.update(completion_options)) end end class FormBuilder def text_field_with_auto_complete(method, tag_options = {}, completion_options = {}) @template.text_field_with_auto_complete_mod(@object_name, method, objectify_options(tag_options), completion_options) end end end end Don''t forget to include the file in your environment.rb of course. I know some people were looking for a way to get this to work, so I thought it might be helpful if I post it on the mailing list. If you see any bugs or know of a better way, please let me know. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ooh, that code isn''t too readable. Um, I posted it on my website as well: http://detyabozhye.com/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi... I wrote some similar code, and packaged it up into a plugin. See: http://patshaughnessy.net/repeated_auto_complete I also know there are a few other forks of the auto_complete plugin that also solve this same problem, for example: http://warrenseen.com/blog/2009/01/16/rails-auto-complete-with-form_for-and-fields_for-support/ Or just look through the auto_complete forks on github: http://github.com/rails/auto_complete/network/members Hope this helps, - pat On Jan 9, 9:23 pm, alyoshka <anime4chr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Ooh, that code isn''t too readable. Um, I posted it on my website as > well:http://detyabozhye.com/--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hmm, maybe we could some parts together. I like the one in the second link, but looking at the code, I think there''s more extra in there. I would still need to check it out more thoroughly. One thing I would like to do is extend the autocomplete functionality to autocomplete for a whole object. eg: If you have an Address model which contains street, city, region, zip. In a form you start typing the street and the autocomplete popup comes up with the full address. When you choose the address, it automatically fills in all the fields for the address. Has anybody done that yet and is it possible to do it easily with Prototype? On Feb 5, 8:34 pm, Pat <p...-TqfKzuDnBR2xH1ktNt+OzKxOck334EZe@public.gmane.org> wrote:> Hi... I wrote some similar code, and packaged it up into a plugin. > See:http://patshaughnessy.net/repeated_auto_complete > > I also know there are a few other forks of the auto_complete plugin > that also solve this same problem, for example:http://warrenseen.com/blog/2009/01/16/rails-auto-complete-with-form_f... > > Or just look through the auto_complete forks on github:http://github.com/rails/auto_complete/network/members > > Hope this helps, - pat > > On Jan 9, 9:23 pm, alyoshka <anime4chr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Ooh, that code isn''t too readable. Um, I posted it on my website as > > well:http://detyabozhye.com/--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---