Polymer: manually submitting a form

forms, manual, polymer-1.0, submit

Solution

From the MDN page about `submit`:

The form's onsubmit event handler will not be triggered when invoking this method ... it is not guaranteed to be invoked by HTML user agents.

However, calling `click` on a `submit` type button seems to work. See here:

http://jsbin.com/tuxac/2/edit

Here is a modification of your jsbin that I believe does what you want:

http://jsbin.com/wadihija/6/edit

Problem

In polymer I'm trying to manually submit a form. My form looks like this: ``` <form id="myForm" on-submit="{{ submitForm }}"> <input class="text" value="{{ someValue}}"> <button type="submit">Submit</button> </form> ``` And in the polymer object I have: ``` submitForm: function(e) { e.preventDefault(); } ``` Whenever I try to do the following: ``` document.getElementById('myForm').submit(); ``` the form totally ignores the on-submit attribute and posts the form to a new page. I'm building a on-screen keyboard for anyone wondering why I would want to do this. I need to submit the form whenever someone hits the enter key on the on-screen keyboard. Does anyone know why this happens? A JSBin example to show you the exact problem (see the alerts): http://jsbin.com/wadihija/2/

Original source