React-hook-form: Form won't trigger onSubmit upon press enter in textarea

Created on 30 Jan 2020  路  1Comment  路  Source: react-hook-form/react-hook-form

Please consider answer the question at spectrum channel.

https://spectrum.chat/react-hook-form/help/submit-form-on-textarea-keypress-enter-event~e18bc0a1-d013-4828-895c-2eb00908b00f

Describe the question?
I have a textarea in the form and I want to trigger the form onSubmit when user press Enter

<textarea
       name={variable}
       ref={register}
       onKeyPress={handleUserKeyPress}
       rows="4"
       defaultValue={submittedValue}
/>

and here is the handleUserKeyPress function

const handleUserKeyPress = e => {
    if (e.key === "Enter" && !e.shiftKey) {
      // e.preventDefault();
      handleSubmit(onSubmit); // this won't be triggered
    }
};
question

Most helpful comment

handleSubmit(onSubmit)();

>All comments

handleSubmit(onSubmit)();

Was this page helpful?
0 / 5 - 0 ratings