简体   繁体   English

riotjs触发表单onsubmit

[英]riotjs trigger form onsubmit

So I have a simple form in RiotJS 所以我在RiotJS有一个简单的表格

<tag-form>
  <form onsubmit={handleSubmit} id='someForm'>
    <input name='param1' />
    <button type="submit">Submit</button>
  </form">
  <script>
    this.handleSubmit=function(e) { console.log(e); }
  </script>
</tag-form>

That works just fine when I submit via the button. 当我通过按钮提交时,效果很好。 But when I use an external button to trigger the submit of the form 但是当我使用外部按钮触发表单的提交时

document.getElementById('someForm').submit();

it doesn't work because it somehow does not run the riotjs onsubmit function, but the native submit function, which is not what I want... 它不起作用,因为它不以某种方式不运行riotjs onsubmit函数,而是本地submit函数,这不是我想要的...

How to fix that? 如何解决?

After some fiddling I fixed it like this: 经过一番摆弄之后,我像这样修复了它:

<tag-form>
  <form onsubmit={handleSubmit} id='someForm'>
    <input name='param1' />
    <button type="submit" id="someButton">Submit</button>
  </form">
  <script>
    this.handleSubmit=function(e) { console.log(e); }
  </script>
</tag-form>

and then call .click() on the button, instead of .submit() on the form. 然后调用.click()上的按钮,而不是.submit()的形式。

document.getElementById('someButton').click();

This seems to work fine! 这似乎工作正常!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM