I have multiple form in a Screen. Need to submit form while onBlur event calling without using ref, because i have multiple and dynamic forms.
Asked
Active
Viewed 251 times
1
-
1You can still use ref with multiple forms; have you tried that? – Chris Cousins May 17 '18 at 12:35
-
Thanks for your response Chris. Its a dynamic form. – user3129330 May 17 '18 at 12:51
1 Answers
0
You may add onBlur event, get access to DOM-element Form and then do submit 'form.submit()':
const myForm = () =>
<input onBlur={(e) => {
// if click occurs outside of element
if(!e.relatedTarget || (e.target.form !== e.activeTarget))
//attention: your page will reload every such instant submission
e.target.form.submit();
}
}} ... (other props) >
...
</form>
Or you need to use
<form onSubmit={(e) => {
e.preventDefault();
...
}>
<input onBlur={(e) => {
...
e.target.form.requestSubmit();
} />
...
the detail of this solution are here Here is my question

Alexey Nikonov
- 4,958
- 5
- 39
- 66