Polymer: manually submitting a form

微笑、不失礼 提交于 2019-12-01 17:28:42

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

Is this along the lines of what you're trying to do? This is a result of a key feature of Shadow DOM: Encapsulation. The elements in your polymer-element's template are not in the main document, and as such, are not available via document.getElementById() and the like.

You could instead call this.shadowRoot.getElementById() and it would work because this inside of your polymer-element's prototype is linked to the host element. Or even better, take advantage of the amazing features Polymer gives you for free. Polymer exposes this.$ to polymer-elements, which contains a key for every element in your template that has an ID! No method call needed, just use this.$.myForm.submit(). Here's the final jsbin.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!