I have the following partial, listed at the bottom of this post. It
has a Javascript function with it, and a select, and an observe field
on the select.
Everything works fine when it is loaded with the entire page, but
rendering the partial alone, of course, the javascript will not
execute. How can I force the javascript function to execuste when I do
subsequent
render :partial => 'thispartial'
Yes but I need to know how to call it.. I would call it onload= in the
html options, but it is not loading -- it is rendering a partial. So
what is the event call that will have it be called when the partial
reloads? -RVince
beacuse javascript functions in partial will only execuate when the
parent document is onload() -- not the partial itself on subsequent
loads of a partial.
THank you for your help, but both of these solutions result in the
same problem. THe javascript in the partial is only executed when the
partial is loaded the first time. Subsequent render :partial =>.. it
does not execute. -RVince
Thank you Hassan -- perhaps I am doing something stupid and not
realising it? It is failing for me in Firefox (latest version) and
Chrome (latest version) I have not tested MSIE. I am running Rails
2.3.2.
I have a partial, /channels/_channelnotesfield.html.erb, with
javascript, as follows:
First, make sure you're running Firebug with FF so you can see if
any JS errors are causing your script(s) to exit.
Second, in my simple test case I have the following:
<%= link_to_remote 'Get another opinion',
:url => {:action =>'opinion', :method => 'get'}, :update => 'things/opinion' %>
<%= render :partial => 'opinion' %>
Yes, I think I almost have it now. In my controller I have replaced
render :partial => 'channelnotesfield'
with what you have:
render :update do |page|
page.replace 'channelnotesfield' , :partial =>
'channelnotesfield'
end
And that does seem to invoke things. However, when I do it your way
not, on subsequent calls to replace channelnotesfield in my
controller, I get a dialog box that says:
RJS Error:
TypeError: element is null
Clicking OK, another dialog box appears, saying:
Element.replace("blah blah the code of my partial")
All I am doing is calling my partial /views/channels/
_channelnotesfield.html.erb from the controller ChannelsController as
shown above. Any idea what I dont have quite right here? Thanks again!
-RVince
I got it!!! Thanks for your patience and perisistence -- I never would
have gotten it if not for you.
In my controller, I was replacing the partial with the partial, when I
should have been replacing the div with the partial as in:
I got it!!! Thanks for your patience and perisistence -- I never would
have gotten it if not for you.
In my controller, I was replacing the partial with the partial, when I
should have been replacing the div with the partial as in:
Yes, I always use firebug, but how could I have used it to have
debugged this?
Every situation is different, of course, but the JavaScript console
showing errors (e.g. trying to reference a non-existent object) and
(for AJAX interactions) the network console showing requests and
responses usually helps me understand what's happening that's
different from what I *think* is happening