react-native-phone-number-input
react-native-phone-number-input copied to clipboard
onSubmitEditing (feature request)
Hello,
Is there any way to implement the input onSubmitEditing callback? Or a workaround to achieve this behaviour? So when you press the Enter/Next button, the focus moves to the next input field.
I have a registration form with multiple input fields and would like to apply this behaviour for my phone field, but I'm currently not able to achieve this.
Thanks in advance!
It's possible using textInputProps:
const textInputProps={ onSubmitEditing: () => ref.current?.focus() }
return(
<PhoneInput
{...rest}
textInputProps={textInputProps}
/>
)
doesn't work
@domoretrix did you define and set the ref?
const ref = useRef(null)
return <TextInput ref={ref} />
yes. Only onBlur and onFocus works for textInputProps
@domoretrix can you copy/paste your code here?
const textInputProps={ onSubmitEditing: () => tiRef.current?.focus() }
return(
<PhoneInput
{...rest}
textInputProps={textInputProps}
/>
<TextInput
ref={tiRef}
>
)
Try this:
const tiRef = useRef(null)
const textInputProps={
onSubmitEditing: () => tiRef.current?.focus()
}
return(
<>
<PhoneInput
{...rest}
textInputProps={textInputProps}
/>
<TextInput
ref={tiRef}
/>
</>
)
ya, i mean of course const tiRef = useRef(null). I omitted this line for showcase purposes. Point is, adding any other property than onBlur or onFocus on textInputProps does not work.
@10000multiplier sorry, you are actually right, your solution does work. I think my simulator is lagging a bit and sometimes it does not carry the changes, so that's why it was confusing for me.
Try this:
const tiRef = useRef(null) const textInputProps={ onSubmitEditing: () => tiRef.current?.focus() } return( <> <PhoneInput {...rest} textInputProps={textInputProps} /> <TextInput ref={tiRef} /> </> )
Where do you import this <TextInput /> ? Thanks!