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
Post a Comment