Case ce-0067-contenteditable-with-form · Scenario scenario-form-integration

contenteditable content is not included in form submission

OS: macOS 14.0 Device: Desktop Any Browser: Chrome 120.0 Keyboard: US Status: confirmed
form submission data-loss chrome

Phenomenon

Standard HTML forms do not recognize contenteditable regions as valid input fields. When the form is submitted via a standard submit button, the value within the editor is ignored, leading to data loss unless handled programmatically.

Reproduction Steps

  1. Place a <div contenteditable="true"> inside a <form>.
  2. Add a <button type="submit">.
  3. Type text into the div and click submit.
  4. Observe that the submitted request payload contains no key/value for the editor content.

Observed Behavior

  • Browsers only include elements with a name attribute that are part of the “Form-associated elements” category.
  • contenteditable is a global attribute and does not turn an element into a form-associated one.

Expected Behavior

The editor content should be treatable as a form value, ideally via an internal hidden field or the ElementInternals API.

Solution

Use a hidden input field that syncs on every input event:

const editor = document.querySelector('[contenteditable]');
const hiddenInput = document.querySelector('input[name="editor-content"]');
editor.addEventListener('input', () => {
   hiddenInput.value = editor.innerHTML;
});

Playground for this case

Use the reported environment as a reference and record what happens in your environment while interacting with the editable area.

Reported environment
OS: macOS 14.0
Device: Desktop Any
Browser: Chrome 120.0
Keyboard: US
Your environment
Sample HTML:
Event log
Use this log together with the case description when filing or updating an issue.
0 events
Interact with the editable area to see events here.

Comments & Discussion

Have questions, suggestions, or want to share your experience? Join the discussion below.