Form of iron with polymer 2.0

I have an error, I am replicating the error in jsbin: https://jsbin.com/micinalacu/1/edit?html,console,output

The iron form, when you send the serialize method, always returns undefined, and it calls twice.

<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> 

Update

The polymer team had to change the method name for serializeForm because they had an error. Source: https://github.com/PolymerElements/iron-form/issues/174

But I continue with the problem that the dispatch event that he called twice Error → https://jsbin.com/koyelafeze/1/edit?html,console,output

+5
source share
1 answer

According to the documentation , the use of a standard <button> element in the form will be automatically submitted.

You should then use <paper-button> , as suggested in the link, or comment on the contents of your cenas() method.

JS Bin Example

+2
source

Source: https://habr.com/ru/post/1266028/


All Articles