javascript - Ruby on rails - Load more button with kaminari and search form. Jquery problems -


i have ajax search form , ajax pagination using kaminari. change 'load more' button i'm having trouble jquery.

for form , normal pagination using in index.js.erb ;

$('.gig-search-list').html("<%= j render(partial: 'gigs') %>"); 

this replaces current results new results search form, or next page being selected kaminari gem.


i have 'load more' button add results bottom of page, still have search form behave before.

with example below, 'load more' button works desired, search form doesn't work @ all.

 $('.gig-search-list').append("<%= j render(partial: 'gigs') %>"); 

i tried separating them....

$("#gig_search_form").submit(function() {     $('.gig-search-list').html("<%= j render(partial: 'gigs') %>")             $('#map').html('<%= j render("map") %>'); });  $(".pagination").click(function(){         $(".gig-search-list").append("<%= j render(partial: 'gigs') %>");         $('#map').html('<%= j render("map") %>'); }); 

this kind of works...a bit.... although have click twice, or submit form twice functions fire. pagination part doesn't take account search parameters , search on place too.


how can combine 2 functions? use .html search form , .append pagination?

you can check condition in index.js.erb, whether got params[:page] or not.

eg. index.js.erb

<% if params[:page] %> #if clicked on load more, params[:page]  $('.gig-search-list').append("<%= j render(partial: 'gigs') %>"); <% else %>  $('.gig-search-list').html("<%= j render(partial: 'gigs') %>"); <% end %> 

when click on pagination wee need append results, can check condition on js.erb


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -