I'm on TS-React project, i got some inputs where scanning some barecode value. I'm using react-hook-form and the useForm Hook. I got some little form (one input-text and one submit button) in a global form and i want to have an automation, when i press "Enter" on keyboard an action/event sends some fetch, or others.
With the and {handleSubmit} = useForm() , it work perfectly but, my input stay in focused and i need lost this focus...
So, how can i do this action ? i saw the blur() function but i didn't success to target my input from the handleSubmit function
import {Controller, useForm} from "react-hook-form"
const BasketContainer: FC = () => {
const { control, handleSubmit, setValue, watch, getValues, reset, formState: {errors}} = useForm<Basket>()
const handleScanIdSubmit = (data: any) => {
// Here my blur action
}
return (
<form onSubmit={handleSubmit(handleScanIdSubmit)}>
<Controller
render={({field: {ref, ...rest}}) => (
<InputText {...rest}
type={"text"}
label={"ID"}
errorMessage={errors.scanId.message}
/>)}
control={control}
name="scanId"
defaultValue={""}
rules={{required: "Field required"}}
/>
<Button type="submit"
/>
</form>
In advance, thanks for helps contributions :)