Problem/Motivation

Currently it is impossible to trigger a refresh of a block after it has been initially loaded, unless you've set a refresh interval.

This happens because the entire block is replaced with the new block contents.

// Replacing block contents.
if (drupalSettings.block_ajax.blocks[blockId].block_ajax.refresh_block) {
  $block.html(data.content);
} else {
  $block.replaceWith(data.content);
}

This means that the RefreshAjaxBlock event is bound to an element that will not exist after the contents have been loaded.

$block.on('RefreshAjaxBlock', function () {
  // Execute the handler payload.
  ajaxBlockHandler($(this));
})

So this won't work:

$('#block-my-block').trigger('RefreshAjaxBlock');

Steps to reproduce

Proposed resolution

Don't remove the outer div.

Remaining tasks

User interface changes

API changes

Data model changes

Issue fork block_ajax-3351439

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

imclean created an issue. See original summary.

imclean’s picture

Status: Active » Needs review
StatusFileSize
new679 bytes
grevil’s picture

Status: Needs review » Reviewed & tested by the community

I just ran into the same problem. The provided patch LGTM. This way we never remove the "block-ajax-placeholder" but it also wasn't removed before, when "refresh_block" and doesn't seem to cause any trouble.

RTBC!

anybody’s picture

grevil’s picture

Created an MR for easier review.

anybody’s picture

Totally makes sense to have this consistent. Also for outer callability. Confirming RTBC.
Can we get this merged?

  • anybody committed 158ca1b8 on 3.x authored by grevil
    Issue #3351439 by imclean, grevil, anybody: Impossible to trigger a...
anybody’s picture

Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.