Value of text_with_auto_complete_field for field observer

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.

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

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

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs