Skip to content
Advertisement

How to prevent page reload using form.submit() to submit as a method in ReactJs

How to prevent page refreshing on firing form submission programmatically in ReactJS? I’ve tried this code:

JavaScript

My goal is to submit form onBlur from this form (when a user fills all the fields and clicks outside of the form)

I’ve already checked these solutions but they dont work:

Prevent page reload when submit

I dont consider iframes Submit form without page reloading

Advertisement

Answer

You should use e.currentTarget.requestSubmit() (docs). Read about differences with submit method here.

Or you may simply define a submit handler function and provide it to both onBlur and onSubmit form properties.

JavaScript

Without resorting to native form submission. If your use case allows that.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement