AJAX and dynamic select lists

Hey there :slight_smile:
Ive got clients and domains and a form containing this:

<%=
@clients = Client.find(:all, :order => “business_name”)
collection_select(:service, :client_id, @clients, :id, :business_name)
%>

Then Ive got an observer field:

<%=observe_field(“service[client_id]”, :update => :domains_container,
:url => {:action => :ajax_domains}, :on => “changed”) %>

and the 2nd select

<%= @domains = Domain.find(:all, :order => "name ASC").map {|d| [d.name, d.id]} select(:service, :domain_id, domains) %>

And the controller bit:
def ajax_domains
render_text(“test”)
end

For some reason “test” doesnt appear anywhere. it doesnt look like the
observer is working.

Any clues?

Petr

And I do have

<%=javascript_include_tag :defaults%>

In the layout.

Petr J. wrote:

Hey there :slight_smile:
Ive got clients and domains and a form containing this:

<%=
@clients = Client.find(:all, :order => “business_name”)
collection_select(:service, :client_id, @clients, :id, :business_name)
%>

When I look at the HTML produced by

collection_select(:service, :client_id, ['1','2','3'], :to_s,:to_i)

I get

1 2 3

Then Ive got an observer field:

<%=observe_field(“service[client_id]”, :update => :domains_container,
:url => {:action => :ajax_domains}, :on => “changed”) %>

So it seems your observe_field should go for the id service_client_id,
and not service[client_id]

Stephan