JS Error - Uncaught TypeError: Cannot read properties of null (reading 'checked')

Created on 1 March 2023, over 1 year ago
Updated 20 June 2023, about 1 year ago

Problem/Motivation

I get this on the layout builder page

drupal.js?v=9.4.11:16 Uncaught TypeError: Cannot read properties of null (reading 'checked')
at gin_lb_js.js?v=9.4.11:1:3287
at Array.forEach ()
at Object.attach (gin_lb_js.js?v=9.4.11:1:3039)
at drupal.js?v=9.4.11:27:24
at Array.forEach ()
at Drupal.attachBehaviors (drupal.js?v=9.4.11:24:34)
at HTMLDocument. (js_defer.js?rqtk3j:4:14)
(anonymous) @ gin_lb_js.js?v=9.4.11:1
attach @ gin_lb_js.js?v=9.4.11:1
(anonymous) @ drupal.js?v=9.4.11:27
Drupal.attachBehaviors @ drupal.js?v=9.4.11:24
(anonymous) @ js_defer.js?rqtk3j:4
setTimeout (async)
Drupal.throwError @ drupal.js?v=9.4.11:15
(anonymous) @ drupal.js?v=9.4.11:29
Drupal.attachBehaviors @ drupal.js?v=9.4.11:24
(anonymous) @ js_defer.js?rqtk3j:4

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Closed: duplicate

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States SocialNicheGuru

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

Comments & Activities

  • Issue created by @SocialNicheGuru
  • πŸ‡ͺπŸ‡ΈSpain Peacog

    I am seeing this error too. The javascript error is caused by lines 10 and 11 in gin_lb_preview_regions.js. The expected elements with id #glb-toolbar-preview-regions and #glb-toolbar-preview-content don't exist. The elements don't exist because gin_lb_preprocess_toolbar__gin_lb is never called.

  • πŸ‡ΊπŸ‡ΈUnited States jessehs Taos, New Mexico

    I encountered this error, along with the symptom that the the "Show content preview" checkbox was missing (in both the sidebar and the toolbar at the top).

    The problem was that the parent theme of the frontend theme, Radix, was preprocessing the form element using HOOK_preprocess_form_element, and moving the input/checkbox into the label template. So since gin_lb overrides these two templates, that preprocess was messing up gin_lb's templates.

    The solution was to patch the Radix theme to return if the #gin_lb_form element was present:

    /**
     * Implements template_preprocess_form_element().
     */
    function radix_preprocess_form_element(&$variables) {
      // Layout-builder related form elements should be left untouched.
      if (!empty($variables['element']['#gin_lb_form'])) {
        return;
      }
    
      // Render the form element inside the label for checkbox and radio.
      if (in_array($variables['element']['#type'], ['checkbox', 'radio'])) {
        $variables['label']['#children'] = $variables['children'];
        unset($variables['children']);
      }
    }
    
  • πŸ‡©πŸ‡ͺGermany berliner

    There is a simple patch to fix this issue available in ✨ Prevent JS errors when Layout Builder is not initially displayed but loaded later via ajax Fixed

  • Status changed to Closed: duplicate about 1 year ago
  • πŸ‡©πŸ‡ͺGermany Christian.wiedemann

    I will mark it as duplicate. Feel free to reopen it if I am wrong.

Production build 0.69.0 2024