# Auto complete form

**URL:** <https://www.ruby-forum.com/t/auto-complete-form/159059>\
**Category:** Rails\
**Created:** [January 30, 2009, 11:46pm UTC](https://www.ruby-forum.com/t/auto-complete-form/159059 "2009-01-30T23:46:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![giga](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b9bd4f/32.png) [@giga](https://www.ruby-forum.com/u/giga)\
**Post date:** [January 30, 2009, 11:46pm UTC](https://www.ruby-forum.com/t/auto-complete-form/159059/1 "2009-01-30T23:46:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![giga](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b9bd4f/32.png) [@giga](https://www.ruby-forum.com/u/giga)\
**Post date:** [January 31, 2009, 3:00am UTC](https://www.ruby-forum.com/t/auto-complete-form/159059/2 "2009-01-31T03:00:42Z")

</div>

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.
