Walter, thanks for your help. I'll try to modify my code to this approach. Thank you.
On Wednesday, April 22, 2015 at 9:29:56 AM UTC-3, Walter Lee Davis wrote: > > > > On Apr 22, 2015, at 8:18 AM, Gm <[email protected] <javascript:>> wrote: > > Hi, > > I have this simple function inside a js file: > > $('input:button').click(function() { > $('#panel').removeClass('hidden'); > }); > > When I render a partial with a button inside: > > <input type="button" value="Save"> > > The click function inside js.file is not executed. > I think it's because the js file is "included" in the main page, and > inside the partial that js is not available. > > > Almost. It's because that js has already 'seen' the page, and your button > wasn't in it when it 'looked', so it didn't register the click handler on > it. Take a look at the deferred listener functions, using the on() method > in jQuery or Prototype. Those let you set up a listener at a higher level > (like the page, or just a parent to the element in your partial), and then > it doesn't matter if the button was injected after the fact or not. > > In Prototype: > > document.on('click', 'input[type="button"]', function(evt, elm){ > // do something > }); > > Walter > > > On Wednesday, April 22, 2015 at 9:10:49 AM UTC-3, Walter Lee Davis wrote: >> >> >> >> On Apr 22, 2015, at 7:40 AM, Gm <[email protected]> wrote: >> >> Hi, >> >> I have a lot of javascript functions that can't be executed when I render >> a partial. >> I mean. There are functions that area described inside a js file and when >> a partial that calls some functions from that file is rendered, nothing >> occurs. >> >> How can I execute a javascript function when a partial is rendered ? >> >> >> Can you say a little more about how you are rendering these partials? Are >> you using remote: true to inject them into the page with JavaScript views, >> or are you rendering the whole page? If the latter, are you using >> Turbolinks? You may need to wrap your JavaScript in an event listener for >> the page:change event. >> >> Walter >> >> >> >> Thanks. >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Ruby on Rails: Talk" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> To post to this group, send email to [email protected]. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/rubyonrails-talk/5085892d-7cd6-4a65-9b1e-1fc0221101d4%40googlegroups.com >> >> <https://groups.google.com/d/msgid/rubyonrails-talk/5085892d-7cd6-4a65-9b1e-1fc0221101d4%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> >> -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected] <javascript:>. > To post to this group, send email to [email protected] > <javascript:>. > To view this discussion on the web visit > https://groups.google.com/d/msgid/rubyonrails-talk/4161aa32-06a0-446d-ac21-567b3699322b%40googlegroups.com > > <https://groups.google.com/d/msgid/rubyonrails-talk/4161aa32-06a0-446d-ac21-567b3699322b%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/31c64a82-13b1-42c4-a41f-02f9065e859e%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.

