Problem/Motivation

Displaying a tabledrag, the following error is displayed in the console:

Uncaught TypeError: this.$toggleWeightButton is undefined

Since 23 July 2020, a new way to display tabledrag has been commited on core #3084916: Add a new Drupal.theme JavaScript function for theming the the show/hide row weight toggle and its wrapper in draggable tables, explained in changelog #3160782: Tabledrag's show/hide weights button is now rendered by theme functions.

Bootstrap extends Drupal.tableDrag and call its parent initColumns() method. This method will call itself the displayColumns method which expect $toggleWeightButton to be a jQuery object.

// In Drupal core/misc/tabledrag.js.
  Drupal.tableDrag.prototype.displayColumns = function (displayWeight) {
    if (displayWeight) {
      this.showColumns();
    } else {
        this.hideColumns();
      }

    this.$toggleWeightButton.html(Drupal.theme('toggleButtonContent', displayWeight));
    $('table').findOnce('tabledrag').trigger('columnschange', !!displayWeight);
  };

Otherwise, during its override, Bootstrap does not initiate this property.

// In bootstrap js/misc/tabledrag.js.
    // Initialize the specified columns (for example, weight or parent columns)
    // to show or hide according to user preference. This aids accessibility
    // so that, e.g., screen reader users can choose to enter weight values and
    // manipulate form elements directly, rather than using drag-and-drop..
    self.initColumns();

Steps to reproduce

Open the console in your browser development tools to display javascript errors.
Display a form with drag&drop field in bootstrap theme.

Proposed resolution

Initiate and use the Object.$toggleWeightButton instead of define its own $button variable.

Issue fork bootstrap-3209773

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

GoZ created an issue. See original summary.

goz’s picture

Status: Active » Needs review
markus_petrux’s picture

Applied the patch on a Drupal 9.1 installation, and it works like a charm. Thank you!

However, it probably needs to be tested with D8, since Bootstrap 8-x.3.x is flagged to support D8 as well.

ronrons’s picture

Applied the patch on a Drupal 9.2.2 and Bootstrap 8.x-3.23 installation, and it works fine. Thank you!

deaom’s picture

Status: Needs review » Reviewed & tested by the community

Also applied the patch to Drupal core 9.2.4 with the Bootstrap 3.23.0 and it's working, did not test with D8.

joel_osc’s picture

This patch also worked for me whereas other approaches did not, for example #3168744: Table drag broken on 9.1.x left me with no text on my toggle button. Here is a patch file for composer installs.

  • markhalliwell committed 38ea0fd on 8.x-3.x authored by GoZ
    Issue #3209773 by GoZ, joel_osc: this.$toggleWeightBUtton is undefined
    
markhalliwell’s picture

Status: Reviewed & tested by the community » Fixed

  • markhalliwell committed 38ea0fd on 8.x-4.x authored by GoZ
    Issue #3209773 by GoZ, joel_osc: this.$toggleWeightBUtton is undefined
    

Status: Fixed » Closed (fixed)

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

joseph.olstad’s picture

@markhalliwell, a friendly nudge for a tagged release of bootstrap with this fix
possibly 8.x-3.24 ?

Keep up the great work,

Thanks

geraldito’s picture

I still get this error after applying the patch on Entity Reference Fields on Drupal 9.3.6.

geraldito’s picture

Thanks, the issue is resolved in newest update on Bootstrap 8.x-3.24.