反应如何在输入模糊时触发表单提交?

问题描述:

我正在尝试使用HTML5 < input type ="email"/> 验证检查.

I'm trying to make use of the HTML5 <input type="email" /> validation check.

我可以很好地做到这一点:

I can get it working fine doing this:

<form>
  <input type="email" />
  <input type="submit" />
</form>

这将使验证在单击sumbit按钮时起作用.但是,我想在 email 字段模糊时触发表单提交.

This gets the validation to work on clicking the sumbit button. However I'd like to trigger the form to submit upon having my email field blur.

如何在没有提交按钮 onBlur 的情况下触发表单?

How do I trigger the form without a submit button onBlur?

赞:

<form>
  <input type="email" onBlur={/* trigger form submission */} />
</form>

或者,是否有更好的方法可以在输入模糊时执行HTML5电子邮件验证检查?

Alternatively, is there a better approach to performaning the HTML5 email validation check upon input blur?

在表单上放置一个 ref 属性,然后调用Submit函数:

Put a ref attribute on your form and call the submit function:

<form ref="myForm">
  <input type="email" onBlur={this.submitForm.bind(this)} />
</form>

添加功能

submitForm(){
  this.refs['myForm'].submit()
}