Form elements defined outside hierarchy with form='form-id' are not captured by form.elements
See original GitHub issuePrevious 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:
- Created 4 years ago
- Reactions:1
- Comments:19 (10 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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
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