Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h1>debug-formdata</h1>
<form id="form">
    <debug-formdata></debug-formdata>

    <input type="text" name="text1" value="foo" />
    <input type="text" name="text2" value="bar" />
    <input type="text" name="text2" value="baz" />
  <textarea name="longtext"></textarea>
    <input type="checkbox" name="check" checked />
    <input type="checkbox" name="checkbox-with-value" value="banana" checked />
    <my-input name="test"></my-input>
    <button name="intent" value="save">Save</button>
    <button name="intent" value="saveAsCopy">Save As Copy</button>
</form>
              
            
!

CSS

              
                body {
  display: grid;
  gap: 1.5rem;
  padding: 3rem;
  font-family: system-ui, sans-serif;
}

form {
  display: grid;
  gap: 1.5rem;
  justify-items: start;
  align-items: start;
  width: 100%;
  max-width: 500px;
}

              
            
!

JS

              
                // Custom Input
class MyInput extends HTMLElement {
  static formAssociated = true;
  elementInternals = this.attachInternals();

  constructor() {
    super();
    const shadow = this.attachShadow({ mode: "open" });
    shadow.innerHTML = `<input type="color">`;
    this.elementInternals.setFormValue(shadow.querySelector("input").value);
    this.inputHandler = this.inputHandler.bind(this);
    shadow.querySelector("input").addEventListener("input", this.inputHandler);
  }

  inputHandler(event) {
    this.elementInternals.setFormValue(event.target.value);
  }
}

customElements.define("my-input", MyInput);

// DebugFormData custom element

class DebugFormData extends HTMLElement {
  static formAssociated = true;

  constructor() {
    super();
    this.shadow = this.attachShadow({ mode: "open" });
    this.shadow.innerHTML = `<style>:host { display: block; width: 100%; font-family: monospace; }  output { white-space:pre; display: block; max-width: 100%; overflow-x: auto; background: #f0f0f0; padding: 1rem;</style><details open><summary>Debug FormData</summary><output></output></details>`;
    this.codeEl = this.shadow.querySelector("output");
    this.internals_ = this.attachInternals();
    this.updateDebugData = this.updateDebugData.bind(this);
  }

  updateDebugData(event) {
    const formData = new FormData(this.internals_.form);
    this.codeEl.textContent = JSON.stringify([...formData], null, 2);
  }

  connectedCallback() {
    this.internals_.form.addEventListener("input", this.updateDebugData);
    this.updateDebugData();
  }
}

(async function() {
  const undefinedElements = [...document.querySelectorAll(':not(:defined)')].filter(el => el.localName !== 'debug-formdata');
  const elementDefinitions = undefinedElements.map((el) => customElements.whenDefined(el.localName));

  // Wait for all the children to be upgraded
  await Promise.all(elementDefinitions);
  
  // define debugger
  customElements.define("debug-formdata", DebugFormData);
})()
              
            
!
999px

Console