I'm having a bug, I replicate the bug in jsbin: 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.
<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. Source: 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
According to the documentation, the use of a standard <button>
element in the form will submit it automatically.
You should then use a <paper-button>
as suggested in the link, or comment the content of your cenas()
method.