javascriptjqueryruby-on-rails-5filterrific

Correct way to increase timer for filterrific_observe_field


The filterrific gem has this jquery function to search automatically... but being a near complete newb with JS, I haven't been able to figure out how to edit it to fire less often.

I've tried copying the method (and whole file) over to my local js folder to edit it there, and renamed the class on the input field that seems to be the trigger it, but it seems that would stop it from reloading until I clicked elsewhere...

$.fn.filterrific_observe_field = function(frequency, callback) { frequency = frequency * 1000; // translate to milliseconds ...

https://github.com/jhund/filterrific/blob/d1d533cbbe88007dc10bbc251db01a0756573db9/app/assets/javascripts/filterrific/filterrific-jquery.js

Any tips?


Solution

  • You should change the code here:

    $(".filterrific-periodically-observed").filterrific_observe_field(
      0.5, // Change this to 1.0 for 1 second interval.
      Filterrific.submitFilterForm
    );
    

    you could then fork the gem on github, make your changes and use that in your project like:

    gem 'filterrific', :git => 'https://github.com/yourname/filterrific.git'
    

    or make a local copy of the gem make your changes and do:

    gem 'filterrific', :path => '/path/to/filterrific'
    

    both are a bit of a pain to put into production but should work.