admin管理员组文章数量:1336143
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>
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.
How do I trigger the form without a submit button onBlur
?
Like this:
<form>
<input type="email" onBlur={/* trigger form submission */} />
</form>
Alternatively, is there a better approach to performaning the HTML5 email validation check upon input blur?
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>
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.
How do I trigger the form without a submit button onBlur
?
Like this:
<form>
<input type="email" onBlur={/* trigger form submission */} />
</form>
Alternatively, is there a better approach to performaning the HTML5 email validation check upon input blur?
Share Improve this question asked Oct 5, 2018 at 12:22 Barry Michael DoyleBarry Michael Doyle 10.7k32 gold badges98 silver badges159 bronze badges2 Answers
Reset to default 3Put a ref
attribute on your form and call the submit function:
<form ref="myForm">
<input type="email" onBlur={this.submitForm.bind(this)} />
</form>
Add a function:
submitForm(){
this.refs['myForm'].submit()
}
use the native checkValidity
method
<form>
<input type="email" id="a" />
</form>
const a = document.querySelector('#a')
a.addEventListener('blur', e => {
const isValid = e.target.checkValidity()
console.log(isValid)
})
本文标签: javascriptReact how to trigger form submit on input blurStack Overflow
版权声明:本文标题:javascript - React how to trigger form submit on input blur? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742395074a2466757.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论