question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Form elements defined outside hierarchy with form='form-id' are not captured by form.elements

See original GitHub issue

Previous issues (#765 #2368) have addressed this issue resulting in PR #2369 but this fix does not add form elements defined outside form hierarchy with form='form-id' in the form.elements member.

Basic info:

  • Node.js version: 10.15.3
  • jsdom version: 15.1.1

Minimal reproduction case

const { JSDOM } = require('jsdom');

let form = `
    <form id='test-form'></form>
    <input type='text' name='test' form='test-form' />
`;

let dom = new JSDOM(form);
console.log('expecting one form element');
console.log('actual: ' + dom.window.document.forms[0].elements.length); // 0

Repro: https://github.com/FThompson/jsdom-form-attribute-bug

How does similar code behave in browsers?

form.elements detects elements defined outside form hierarchy with form attribute: https://jsfiddle.net/fthompson/2njuLq3r/2/

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:19 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
ccwebdesigncommented, Oct 10, 2019

This seems to fix the issue, if you (JSDOM contributors) want to add it. It needs proper testing (sorry – low on time at the moment).

In master lib/jsdom/living/nodes/HTMLFormElement-impl.js:50

  get elements() {
    // TODO: Return a HTMLFormControlsCollection
    return HTMLCollection.createImpl([], {
      element: this,
-     query: () => domSymbolTree.treeToArray(this, {
+     query: () => domSymbolTree.treeToArray(this.ownerDocument, {
-       filter: node => isListed(node) && (node._localName !== "input" || node.type !== "image")
+       filter: node => isListed(node) && (node._localName !== "input" || node.type !== "image") && this == node.form
      })
    });
  }
1reaction
timrobinson33commented, May 22, 2020

I’ve raised another bug which I think could be related https://github.com/jsdom/jsdom/issues/2979. - the form validation also excludes controls that aren’t physically nested inside the form

Read more comments on GitHub >

github_iconTop Results From Across the Web

The Form element - HTML: HyperText Markup Language | MDN
The HTML element represents a document section containing interactive controls for submitting information.
Read more >
Forms in HTML documents - W3C
An HTML form is a section of a document containing normal content, markup, special elements called controls (checkboxes, radio buttons, menus, etc.) ...
Read more >
html5 input pattern attribute not working outside a form?
It seems the input's pattern attribute needs a form to validate. By the way, I'm doing a complex page without forms and I'...
Read more >
The Form voice element is used to capture any input ... - Cisco
voice element does not capture the information desired, one can always use a Form element before ... Defines an external voice grammar for...
Read more >
Using forms in ColdFusion - Adobe Support
cfslider Lets users input data by moving a sliding marker. cftree Displays data in a hierarchical tree format with graphical indicators; can get ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found