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.
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | bootstrap-toggle_undefined-3209773-8.patch | 1.16 KB | joel_osc |
Issue fork bootstrap-3209773
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
Comment #3
goz commentedComment #4
goz commentedComment #5
markus_petrux commentedApplied 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.
Comment #6
ronrons commentedApplied the patch on a Drupal 9.2.2 and Bootstrap 8.x-3.23 installation, and it works fine. Thank you!
Comment #7
deaom commentedAlso applied the patch to Drupal core 9.2.4 with the Bootstrap 3.23.0 and it's working, did not test with D8.
Comment #8
joel_osc commentedThis 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.
Comment #10
markhalliwellComment #13
joseph.olstad@markhalliwell, a friendly nudge for a tagged release of bootstrap with this fix
possibly 8.x-3.24 ?
Keep up the great work,
Thanks
Comment #14
geraldito commentedI still get this error after applying the patch on Entity Reference Fields on Drupal 9.3.6.
Comment #15
geraldito commentedThanks, the issue is resolved in newest update on Bootstrap 8.x-3.24.