Forum: Ruby on Rails Auto complete form

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.
Fresh M. (Guest)
on 2009-01-31 00:46
If I have table user (id, firstname, lastname, age, city)

And form: textboxes for firstname, lastname, age and select for city

Is it possible to auto complete form? Not only firstname or lastname,
but full form?
So if I enter lastname, and there is only one user with this name, so it
auto complete firstname, age and city.
David S. (Guest)
on 2009-01-31 04:00
James B. wrote:
> If I have table user (id, firstname, lastname, age, city)
>
> And form: textboxes for firstname, lastname, age and select for city
>
> Is it possible to auto complete form? Not only firstname or lastname,
> but full form?
> So if I enter lastname, and there is only one user with this name, so it
> auto complete firstname, age and city.

Hello there,
Why don't you try a form_observer to do the job?

Simple example:
(view)
<% form_for :foo, :id => "my_form" %>
   <%= form.text_field :first_name%>
   <%= form.text_field :last_name%>
   <%= form.text_field :age%>
<% end %>
<%= observe_form :my_form, :frequency => 0.5, :url => {:action =>
search_result" } %>

(controller)
def search_result
   @foo = User.find(:all, :conditions => ["first_name LIKE ?, last_name
LIKE ?",params[:first_name], params[:last_name]])
   render view again
end


I don't now if what you want to do is a good idea, but.... that is the
way I'll do it (what does not mean that is the best way, I'm new in
Rails).

David S.
This topic is locked and can not be replied to.