Drupal once usage for dialog:beforeclose event binding

Created on 20 March 2023, over 1 year ago

Problem/Motivation

When configuring a patternkit block with existing layout, there is JS console error. Subsequently, I'm unable to save changes the the patternkit block configuration.

The dialog:beforeclose event binding here, appears to implement Drupal's once incorrectly.

This Drupal core change record β†’ states

You can only use once with objects that are instances of Element, which means you can not use it with the document or window object.

.

And the code uses the window object.

$(once('patternkit-jsoneditor-off-canvas', window)).on('dialog:beforeclose', (event, dialog, $element) => {

Steps to reproduce

I have not yet been able to reproduced this outside of my implementation using the Patternkit Example with Drupal core only.

TBD

Uncaught TypeError: The element must be an instance of Element
    u once.js:122
    c once.js:189
    c once.js:188
    a once.js:278
    augmentedOnce jQuery
    attach patternkit.jsoneditor.js:1353
    attachBehaviors drupal.js:24
    attachBehaviors drupal.js:21
    insert ajax.js:493
    jQuery 2
    insert ajax.js:491
    openDialog dialog.ajax.js:66
    commandExecutionQueue ajax.js:374
    promise callback*Drupal.Ajax.prototype.commandExecutionQueue/< ajax.js:371
    commandExecutionQueue ajax.js:370
    success ajax.js:395
    success ajax.js:207
    jQuery 6
    eventResponse ajax.js:296
    Ajax ajax.js:247
    jQuery 8
    Ajax ajax.js:241
    ajax ajax.js:105
    bindAjaxLinks ajax.js:134
    bindAjaxLinks ajax.js:117
    <anonymous> contextual.js:150
    jQuery 7
    initContextual contextual.js:77
    attach contextual.js:108
    setTimeout handler*attach/< contextual.js:107
    attach contextual.js:104
    attachBehaviors drupal.js:24
    attachBehaviors drupal.js:21
    <anonymous> drupal.init.js:24
    listener drupal.init.js:14
    domReady drupal.init.js:20
    <anonymous> drupal.init.js:23
    <anonymous> drupal.init.js:26

Proposed resolution

Update the Drupal once usage following the examples in Drupal core change record.

Per the Drupal core change record β†’ ,

If you need a page-level element please use 'html' or 'body' as the selector used in the once call: once('my-global-once', 'html').

There's this example in the change record.
$(once('vertical-tabs-fragments', 'body')).on()

Remaining tasks

TBD

User interface changes

None

API changes

None

Data model changes

None

πŸ› Bug report
Status

Active

Version

9.1

Component

Module Core

Created by

πŸ‡ΊπŸ‡ΈUnited States jasonawant New Orleans, USA

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

Comments & Activities

Production build 0.69.0 2024