Hi Ezra
The code makes sense, but its not working as expected. While I do get
the indicator image showing, the select box never updates. This is the
code:
In the view:-
<%= select (‘task’, ‘parent_id’, @parents.collect {|p| [ p.title, p.id
]},
{ :include_blank => true},
:onchange => remote_function ( :with =>
“‘parent_id=’+value”,
:loading =>
“Element.show(‘loading-indicator’)”,
:url => { :action =>
:select_with_ajax } )) %>
<%= image_tag(‘indicator.gif’,
:id => ‘loading-indicator’,
:style => ‘display:none;’ ) -%>
<%= render :partial => 'client_list' %>
In the controller:-
def select_with_ajax
@clients = Client.find(:all,
:conditions => [“parent_id = ?”,
params[:parent_id]],
:joins => [:tasks])
render :update do |page|
page.replace_html(‘task_client’, :partial => ‘parent_client_list’,
:collection => @clients)
page.hide(‘loading-indicator’)
end
end
And the partial _parent_client_list.rhtml looks like:
<%= select (‘task’, ‘client_id’, @clients.collect {|c| [ c.name, c.id ]
}, { :include_blank => false }) %>
What am I missing?
thx
n.
Ezra Z. wrote:
On Apr 27, 2006, at 7:26 AM, Nick C. wrote:
I’ve come across several part examples using remote_function or
<%= select (‘task’, ‘client_id’, @clients.collect {|c| [ c.name,
c.id ]
}) %>
Nick-
Here is an example of how you can get started doing this:
— In the view file ----
<%= select (‘task’, ‘parent_id’, @parents.collect {|p| [ p.title,
p.id ]},
{ :include_blank => true,
:onchange => remote_function( :with =>
“‘parent_id=’+value”,
:loading => “Element.show(‘loading-
indicator’)”,
:url => { :action
=> :select_with_ajax } )) %>}) %>
<%= image_tag(‘indicator.gif’,
:id => ‘loading-indicator’,
:style => ‘display:none;’ ) -%>
— In the controller action----
def select_with_ajax
@clients = Client.find(:all, :conditions => [“parent_id = ?”,
params[:parent_id])
render :update do |page|
page.replace_html(‘next_select’, :partial =>
‘second_select’, :collection => @clients
page.hide(‘loading-indicator’)
end
end
The loading indicator gif is one of those little spinner animated gif
files. You might need to change the @client=Client.find line to fetch
whatever it is you want to populate the next select box with. And you
will need a partial called _second_select.rhtml that has the code for
the second select box.
Hope that gets you over the hump.
Cheers
-Ezra