Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version >= 5.2.4 don't work with Select2 #218

Open
djpremier opened this issue Apr 7, 2023 · 3 comments
Open

Version >= 5.2.4 don't work with Select2 #218

djpremier opened this issue Apr 7, 2023 · 3 comments

Comments

@djpremier
Copy link

After change of jQuery to Vanilla JS, the change in fields that use Select2 don't trigger filteriffic search.

@0llirocks
Copy link

Could be related to #220? Try adding an empty div with a .filterrific_spinner class.

@GearoidDC
Copy link

I added this to my application.js and it fixed it.
If you are using select2 you have jquery anyway so it shouldn't be a problem using jquery here.
It is just replacing with what the code was before in filterrific.

I'm going to try figure out what the issue is.

Filterrific.init = function() {
  $('#filterrific_filter').on(
    "change",
    ":input:not(.filterrific-periodically-observed)",
    Filterrific.submitFilterForm
  );

 
  Filterrific.observe_field(
    ".filterrific-periodically-observed",
    0.5,
    Filterrific.submitFilterForm
  );
};

jQuery(document).ready(Filterrific.init);
jQuery(document).on('page:load', Filterrific.init);

I also have to replace the submitFilterForm method.

Filterrific.submitFilterForm = function(){
  var form = $(this).parents("form"),
      url = form.attr("action");
  // turn on spinner
  $('.filterrific_spinner').show();
  // Submit ajax request
  $.ajax({
    url: url,
    data: form.serialize(),
    type: 'GET',
    dataType: 'script'
  }).done(function( msg ) {
    $('.filterrific_spinner').hide();
  });
};

@JosephTico
Copy link

This is mostly a select2 issue. This is a very old library whose developers decided for some dumb reason that it won't trigger the standard change event when the select, well, changes.

Here's more info and a workaround:
https://stackoverflow.com/a/77871613/1102840

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants