How to submit a form with polymer?

允我心安 提交于 2019-12-24 04:32:10

问题


I've have this polymer contact-element:

<polymer-element name="contact-element">
  <template>
    <paper-input label="Your Name" id="contact-name" floatingLabel></paper-input>
    <paper-input multiline label="Your text here..." id="contact-message" floatingLabel></paper-input>
    <paper-button label="Send Data" id="contact-submit" raisedButton></paper-button>
  </template>
  <script>
    Polymer({});
  </script>
</polymer-element>

It's included in this index.html

<form action="/sendMessage" method="GET">
        <contact-element></contact-element>
</form>

Is there an submit-attribute for the paper-button or do I have to do the submit with JS?


回答1:


Try the ajax-form element: http://ajax-form.raynicholus.com.

It supports the paper elements.




回答2:


For any future Readers, now that 1.0 is released:

This is basic html form processing. At the time of this writing, Polymer now has the iron-form, but you still submit it like any other form.

<form is="iron-form" id="form" method="post" action="/">

  <paper-input name="testinput"></paper-input>

  <paper-button raised click="document.getElementById('form').submit();">
     Post
  </paper-button>

</form>



回答3:


From Polymer's blog: https://blog.polymer-project.org/featured/2014/09/23/featured-002/

Ray Nicholus’ ajax-form element provides a simple way to submit forms. ajax-form works with traditional form elements, as well as any custom elements that have both a name attribute and a value – including the Core and Paper input elements.

https://github.com/rnicholus/ajax-form http://ajax-form.raynicholus.com




回答4:


Since, as you pointed out, paper-buttons do not extend the native button element, you will have to either write your own JavaScript to handle form submission or wait for the upcoming paper-forms Polymer element.



来源:https://stackoverflow.com/questions/24952217/how-to-submit-a-form-with-polymer

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