[英]Trying to submit iron-form polymer 2 - Cannot read property 'submit' of null
I'm not able to submit my iron-form. 我无法提交我的铁表。 At this point I just need to see the content in the console, but when trying to submit the form i'm only getting error-msg: Uncaught TypeError: Cannot read property 'submit' of null. 此时,我只需要在控制台中查看内容,但是当尝试提交表单时,我只会得到error-msg:Uncaught TypeError:无法读取null的'submit'属性。 I've probably missed something obvious. 我可能错过了一些显而易见的事情。 I've been using the page: https://www.webcomponents.org/element/PolymerElements/iron-form 我一直在使用以下页面: https : //www.webcomponents.org/element/PolymerElements/iron-form
<iron-form id="sizeForm">
<form method="post" action="">
<paper-dropdown-menu label="Choose type" on-iron-select="_typeSelected">
<paper-listbox slot="dropdown-content">
<paper-item value="Sneakers">Sneakers</paper-item>
<paper-item value="Shoes">Shoes</paper-item>
<paper-item value="T-shirts">T-shirts</paper-item>
<paper-item value="Jeans">Jeans</paper-item>
</paper-listbox>
</paper-dropdown-menu>
<add-sneakers hidden$="{{hideSneakers}}"></add-sneakers>
<paper-button onclick="{{_submitForm}}">Accept</paper-button>
<div class="output"></div>
</form>
</iron-form>
<script>
_submitForm() {
document.getElementById('sizeForm').submit();
}
</script>
Change 更改
<paper-button onclick="{{_submitForm}}">Accept</paper-button>
to 至
<paper-button on-tap="_submitForm">Accept</paper-button>
or 要么
<button onclick="_submitForm()">Accept</button>
Also, it seems the iron-form
docs got it wrong: document.getElementById('sizeForm').submit()
works with a button
but not a paper-button
. 而且,似乎iron-form
文档会弄错了: document.getElementById('sizeForm').submit()
使用button
但不使用paper-button
。 this.$.sizeForm.submit()
works with either. this.$.sizeForm.submit()
使用。 (I'll explore this more, and may submit a pull request on it.) (我将对此进行更多的探讨,并可能对此提交拉取请求。)
You need to give the id attribute to the form according to what you have on the javascript. 您需要根据javascript的内容为表单赋予id属性。
<form id="form_name" method="post" action="">
and correct it on the javascript, since the id that you are using on your example is (already) defined before. 并在javascript上对其进行更正,因为您之前在示例中使用的ID已(已经)定义。
document.getElementById('form_name').submit();
So, bottom line, you need to add the id in the form and correct it on the js code. 因此,最重要的是,您需要在表单中 添加 id并在js代码上对其进行更正。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.