# Value of text\_with\_auto\_complete\_field for field observer

**URL:** <https://www.ruby-forum.com/t/value-of-text-with-auto-complete-field-for-field-observer/122946>\
**Category:** Rails\
**Created:** [December 12, 2007, 10:34pm UTC](https://www.ruby-forum.com/t/value-of-text-with-auto-complete-field-for-field-observer/122946 "2007-12-12T22:34:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![d2kagw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b5a626/32.png) [@d2kagw](https://www.ruby-forum.com/u/d2kagw)\
**Post date:** [December 12, 2007, 10:34pm UTC](https://www.ruby-forum.com/t/value-of-text-with-auto-complete-field-for-field-observer/122946/1 "2007-12-12T22:34:35Z")

</div>

I’m trying to use the results of an auto complete form in a field  
observer. The problem is the value of the field is just a select item  
in a UL. So if I have this:

\<%= text\_field\_with\_auto\_complete :school, :name %\>

\<%= observe\_field ‘school\_name’,  
:url =\> {:action =\> ‘get\_students\_by\_school’},  
:update =\> ‘student\_list’,  
:with =\> ‘school[name]’ %\>

I type ‘an’, select ‘Anderson High’ or whatever and the parameters  
look like this:

“school”=\>{“name”=\>“an”}

My latest hack attempt was to have the observer render a  
link\_to\_remote button (‘find school’) with the value of li.selected as  
its id. Couldn’t get that to work.

When you submit the form, obviously the value of the school[name]  
parameter is correct, so I’d like to know how I can recreate this  
functionality in my field observer.

As an aside, I can’t find the documentation on the auto complete  
helper in the API.

---

<div class="post-metadata">

**Author:** ![d2kagw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b5a626/32.png) [@d2kagw](https://www.ruby-forum.com/u/d2kagw)\
**Post date:** [December 13, 2007, 1:54am UTC](https://www.ruby-forum.com/t/value-of-text-with-auto-complete-field-for-field-observer/122946/2 "2007-12-13T01:54:32Z")

</div>

On Dec 12, 2007, at 10:33 PM, Aaron wrote:

> I’m trying to use the results of an auto complete form in a field  
> observer. The problem is the value of the field is just a select item  
> in a UL. So if I have this:
> 
> \<%= text\_field\_with\_auto\_complete :school, :name %\>
> 
> \<%= observe\_field ‘school\_name’,  
> :url =\> {:action =\> ‘get\_students\_by\_school’},  
> :update =\> ‘student\_list’,  
> :with =\> ‘school[name]’ %\>

I guess onchange is not fired because the field is in the end set with  
JavaScript. You’ll surely need to pass some JavaScript for  
the :after\_update\_element hook of the rightmost optional parameter  
completion\_options. That JavaScript would do what you wanted to do  
with the observe\_field, which would be removed.

– fxn

---

<div class="post-metadata">

**Author:** ![d2kagw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b5a626/32.png) [@d2kagw](https://www.ruby-forum.com/u/d2kagw)\
**Post date:** [December 13, 2007, 1:59am UTC](https://www.ruby-forum.com/t/value-of-text-with-auto-complete-field-for-field-observer/122946/3 "2007-12-13T01:59:47Z")

</div>

On Dec 13, 2007, at 1:52 AM, Xavier N. wrote:

> > ```
> > :url => {:action => 'get_students_by_school'},
> > :update => 'student_list',
> > :with => 'school[name]' %>
> > 
> > ```
> 
> I guess onchange is not fired because the field is in the end set  
> with JavaScript. You’ll surely need to pass some JavaScript for  
> the :after\_update\_element hook of the rightmost optional parameter  
> completion\_options. That JavaScript would do what you wanted to do  
> with the observe\_field, which would be removed.

Let me add that with model\_auto\_completer[\*] you could send back the  
school ID instad of the name via its own :after\_update\_element hook.

Depending on the data that would be a better way to get the list of  
students of the school.

– fxn

[\*] [http://agilewebdevelopment.com/plugins/model\_auto\_completer](http://agilewebdevelopment.com/plugins/model_auto_completer)

---

<div class="post-metadata">

**Author:** ![d2kagw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b5a626/32.png) [@d2kagw](https://www.ruby-forum.com/u/d2kagw)\
**Post date:** [December 13, 2007, 2:30am UTC](https://www.ruby-forum.com/t/value-of-text-with-auto-complete-field-for-field-observer/122946/4 "2007-12-13T02:30:13Z")

</div>

Awesome. I’ll try this out and let you know how it goes.
