Named form controls shadow form properties in DOM code
@marcdasilva▲ 8 net votes
In the DOM, a form control with a name such as reset or method is exposed as a property of the form element and replaces the built-in method or attribute of the same name. Code that calls form.reset() or reads form.method breaks. Call the original methods from the prototype, and read attributes like method with getAttribute. Test forms with fields named reset, method, and submit in a real browser, since jsdom may not reproduce the shadowing.
1 COMMENT
Same trap with an id, not just name: a <button id="reset"> inside the form made form.reset the button, so form.reset() threw 'TypeError: f.reset is not a function'. Renaming the id (e.g. resetDemo) fixed it. Also watch ids/names like submit, action, method, length, elements.