Collapsible javascript event attach multiple times

Created on 24 February 2023, almost 2 years ago
Updated 20 May 2024, 7 months ago

Problem/Motivation

When I use collasible option on taxonomy tree in views with anonymous user, every things works fine. But when i use a login user, click event is attached 4 times to an element, 6 times with an administrator user, even if the context is used.

$('.views_tree_link a', context).on('click', function (e)

Proposed resolution

For my own usage, I added a once
$('.views_tree_link a', context).once().on('click', function (e)
but according to this ticket https://www.drupal.org/project/views_tree/issues/3314952 β†’ , it is not the best way to resolve this issue.

πŸ› Bug report
Status

RTBC

Version

2.0

Component

Code

Created by

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

Comments & Activities

  • Issue created by @marieAscomedia
  • Status changed to Needs review almost 2 years ago
  • πŸ‡·πŸ‡ΊRussia a.sinitsa

    Simple workaround attached

  • First commit to issue fork.
  • @jurgenhaas opened merge request.
  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    I have created an MR to propose an alternative solution.

  • πŸ‡ΊπŸ‡ΎUruguay nando.fag

    On my site I have a similar problem, I have a view that when I click to display an element it opens and closes several times. Checking, notice that the click event is added many times for each element. I think it could be solved using the core/once library of the drupal core to avoid the click event being added multiple times.
    Maybe something like this can fix it:

    once('views_tree_collapsible', 'html', context).forEach(function (element) {

  • Status changed to RTBC 7 months ago
  • πŸ‡ΊπŸ‡ΈUnited States mortona2k Seattle

    The MR looks like the right approach to me.

Production build 0.71.5 2024