[英]Iron form with polymer 2.0
I'm having a bug, I replicate the bug in jsbin: https://jsbin.com/micinalacu/1/edit?html,console,output 我有一个bug,我在jsbin中复制了这个bug: https ://jsbin.com/micinalacu/1/edit ? html,console,output
The iron form, when submit the serialize method return always undefined, and it's called two times. 提交serialize方法返回的铁形式总是未定义的,并且它被调用两次。
<dom-module id="my-form">
<template>
<iron-form id="myForm">
<form method="get" action="cenfdsas">
<input type="text" name="cenas">
<button on-click="cenas">Submit</button>
</form>
</iron-form>
</template>
<script>
class MyForm extends Polymer.Element {
static get is() {
return 'my-form';
}
connectedCallback() {
super.connectedCallback();
const form = this.$.myForm;
form.addEventListener('iron-form-presubmit', function (event) {
event.preventDefault();
console.log("here")
console.log(form.serialize());
});
}
cenas() {
this.$.myForm.submit();
}
}
window.customElements.define(MyForm.is, MyForm);
</script>
</dom-module>
Polymer team needed to change the name of the method to serializeForm, because they had a bug. Polymer团队需要将方法的名称更改为serializeForm,因为他们有一个bug。 Source: https://github.com/PolymerElements/iron-form/issues/174
资料来源: https : //github.com/PolymerElements/iron-form/issues/174
But I continue with the issue that the submit event It's called two times Bug --> https://jsbin.com/koyelafeze/1/edit?html,console,output 但我继续讨论提交事件它被称为两次Bug - > https://jsbin.com/koyelafeze/1/edit?html,console,output
According to the documentation , the use of a standard <button>
element in the form will submit it automatically. 根据文档 ,在表单中使用标准的
<button>
元素将自动提交。
You should then use a <paper-button>
as suggested in the link, or comment the content of your cenas()
method. 然后,您应该使用链接中建议的
<paper-button>
,或者评论您的cenas()
方法的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.