0

I'm attempting to use a little bit of jQuery to perform a views reload when a certain flag is clicked.

Updated Problem: The updated code below now works, but requires a timeout. Is there a way of doing this without a timeout? Unless I add the timeout, the second time the event fires, nothing happens, but every time afterward it works.

(function ($, Drupal) {
  Drupal.behaviors.gridNotificationRefresh = {
    attach: function (context) {

      $('a.use-ajax', context).on('click', function(event) {
        setTimeout(function(){
          var unreadCountView = document.getElementsByClassName('view-id-new_content_count');
          $(unreadCountView).trigger('RefreshView');
          return false;
        }, 300);
      });

    }
  };
})(jQuery, Drupal);

Here's the entry in the THEME.libraries.yml file with the dependencies.

notification_refresh:
  version: 8.x-1.0
  js:
    scripts/notification-refresh.js: {}
  dependencies:
    - core/drupal
    - core/jquery
    - core/jquery.once

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.