What seems like a pretty straight forward implementation of ajaxifying a link is not working if I use it in more than one view block on the page.

I have a route that calls a function. In my view I have simple links that hit that route such as:

<a href="/delete/paragraph/81" class="use-ajax">Delete</a>

Here is the Controller

  public function DeleteEntityParagraph($pid) {
    $response = new \Drupal\Core\Ajax\AjaxResponse();
    $response->addCommand(new \Drupal\Core\Ajax\AlertCommand('wtf'));
    // $response->addCommand(new InvokeCommand(NULL, 'refreshView', []));

    return $response;
  }

It all works fine. You click it, it throbs and returns the alert response. But then if I make another view block, with different content, and put it on the same page, the links on the second view do not use the ajax behavior.

The first views links will continue to work with the ajax behavior. If I remove the first view, the second views links will begin to work. Whichever view block occurs first is the only one with working ajax links.

Does anyone have any idea why this happens? Ive searched high and low. Found this issue but I don't think it is related

  • 2
    I am not having such issues on separate views on same page, at least not with ajax modal. IE: <a class="use-ajax" data-dialog-options="{&quot;width&quot;:800}" data-dialog-type="modal" href="/node/1">Node 1</a>. Any errors in the browser console? Are you able to reproduce the issue on a fresh Drupal Install? – No Sssweat Nov 27 at 11:13
  • 1
    Oops yes there was an unrelated error happening from another script which was affecting this. derp! Thanks! – Matt Campbell Nov 27 at 19:20

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.