Jump to content

The ultimate community for Ruby on Rails developers.


Updating DOM with JQuery and a (html)partial Js functions not working after update

Javascript view partial

  • Please log in to reply
No replies to this topic

#1 Aric Walker

Aric Walker


  • Members
  • 1 posts

Posted 06 June 2014 - 05:50 PM

HI All, 

          Just wondering if some one could give me some direction on this..



Standard HTML(erb) view 

View is rendered with a form and a table displayed below.

 Using Respond to Js in controller updating DOM of view with Jquery. After the form is submitted with remote.

An extra JS function is also attached to the button to run on click of the form.  This javaScript function is in the application JS. and works on the first click..

But on the second click it does not fire.


Use Case 

1) On submit of form I do it  :remote.. My extra JS fires along with the form and I am happy.

2) Controller responds to JS and I update the form button and the table inplace with JS file via Jquery  and two partials.  All HTML is exact and good in the JS and partials.

3) Now my button got updated in-place and my table did also and looks good.  Now on second click of submit button the extra JS(thats in the applicaiton.js) does not fire. Form still submits and works and table gets updated and everything looks good besides.

4) The only way to get the extra JS to fire again is to add it to the partial that updates the button.


Is this correct ? or should I still be able to fire on the JS in application.js  Not sure if I am doing this correctly.. Having the code in two places does not seem right to me.



Code from button partial... ( the function is a bootstrap3 function but it could be any javascript function and same behavior)


  <div id="groupostb" class="col-lg-3">
      <%= button_tag 'search',:class => "btn btn-primary ", "data-loading-text"=> "Searching...", :style=>"margin-left:3px;", :id=>"met-btn" %>
       // metrics button
                .click(function () {
                    var btn = $(this)
                    setTimeout(function () {
                    }, 8000)









Also tagged with one or more of these keywords: Javascript, view, partial

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users