Drupal behaviors not attached after ajax content is loaded

Created on 13 February 2023, over 1 year ago
Updated 5 February 2024, 5 months ago

Problem/Motivation

We're having an issue with ajax loaded content.
The content being loaded is not being considered by Drupal JS behaviors.
We see this issue e.g. when using the extlink module β†’ , which doesn't apply the external link icon, when it should.

Proposed resolution

It seems behaviors will be attached only when executing Drupal ajax calls, which is not the case here (see https://drupal.stackexchange.com/questions/270639/drupal-behaviors-not-a...).

My proposed resolution is to add Drupal.attachBehaviors(); after the content has been added to the DOM.

✨ Feature request
Status

Needs review

Version

2.0

Component

Code

Created by

πŸ‡§πŸ‡ͺBelgium Ludo.R Brussels

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @Ludo.R
  • Status changed to Needs review over 1 year ago
  • πŸ‡§πŸ‡ͺBelgium Ludo.R Brussels

    Here's the patch.

  • Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update 5 months ago
    Waiting for branch to pass
  • πŸ‡¬πŸ‡§United Kingdom Baysaa

    Here's a patch for sitewide_alert 2.2.1

    This issue can be seen when you have extlink module installed, and add an external link to a sitewide alert. The external link icon is not attached to the link in the alert on load, but the icon is added after an ajax action occurs such as a modal window opening.

Production build 0.69.0 2024