Support fields without a wrapping <form>

Created on 21 January 2025, 3 months ago

Problem/Motivation

When having a text field with the comments enabled, and without a wrapping form tag, the JS crashes.

I want to have an input without any submit, so I removed the form around the input. This is valid HTML.

Steps to reproduce

Prepare a page containing an input with the comments feature enabled, but not in a form.

E.g. generate a form with $formBuilder->getForm(...), then remove the theme wrappers:

unset($formbuild['content']['#theme_wrappers']);

Display the page.

The JS crashes.

Proposed resolution

In commentAdapter.js, make this code optional with a nullsafe operator:

this.editor.sourceElement.closest('form')?.addEventListener(...)

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

1.3

Component

Plugin: Comments

Created by

🇫🇷France dakwamine

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

Comments & Activities

  • Issue created by @dakwamine
  • 🇵🇱Poland salmonek

    Hi @dakwamine

    Your request seems doable, however ther is I think easier way to remove submit than removing form wrapper. You can remove the submit button itself. For example:

    function MYMODULE_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
      if ($form_id === 'node_page_form') {
        unset($form['actions']['submit']);
        unset($form['actions']['preview']);
      }
    }
    
  • Status changed to Closed: works as designed 30 days ago
  • The solution suggested by @salmonek should resolve the issue. We don't plan to cover this edge case in the module itself for the time being, unless there will be more requests from the community.

Production build 0.71.5 2024