使用表单onsubmit触发聚合物函数?

时间:2015-09-17 23:27:08

标签: polymer-1.0

我无法在提交表单时触发Polymer函数:

<form onsubmit="return _submit()"> //_submit is not defined
<form onsubmit="return this._submit()"> //this._submit is not a function
<form onsubmit="_submit"> //_submit is not defined
<form onsubmit="{{_submit}}"> //no output
<form on-submit="{{_submit}}"> //no output
<form on-submit="_submit">  //no output

如何绑定到Polymer函数?

1 个答案:

答案 0 :(得分:0)

使用iron-form

<form is="iron-form" id="form" method="post" action="/form/handler">
  <paper-input name="name" label="name"></paper-input>
  <input name="address">
  ...
</form>

然后为表单提交后触发的iron-form-submit添加一个监听器:

Polymer({

  listeners: {
    'iron-form-submit': '_handleSubmit'
  },

  _handleSubmit: function(e) {
   // Do something
  }

})

有关详细信息,请参阅iron-form docs