react-native-phone-number-input icon indicating copy to clipboard operation
react-native-phone-number-input copied to clipboard

onSubmitEditing (feature request)

Open timdemeyer opened this issue 4 years ago • 10 comments

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!

timdemeyer avatar Aug 20 '21 13:08 timdemeyer

It's possible using textInputProps:

const textInputProps={ onSubmitEditing: () => ref.current?.focus() }

return(
  <PhoneInput
    {...rest}
    textInputProps={textInputProps}
  />
)

cloudorbush avatar Sep 22 '21 17:09 cloudorbush

doesn't work

domoretrix avatar Dec 09 '21 20:12 domoretrix

@domoretrix did you define and set the ref?

const ref = useRef(null)

return <TextInput ref={ref} />

cloudorbush avatar Dec 09 '21 22:12 cloudorbush

yes. Only onBlur and onFocus works for textInputProps

domoretrix avatar Dec 10 '21 14:12 domoretrix

@domoretrix can you copy/paste your code here?

cloudorbush avatar Dec 10 '21 16:12 cloudorbush

const textInputProps={ onSubmitEditing: () => tiRef.current?.focus() }

return(
  <PhoneInput
    {...rest}
    textInputProps={textInputProps}
  />
 <TextInput
   ref={tiRef}
 >
)

domoretrix avatar Dec 10 '21 17:12 domoretrix

Try this:


const tiRef = useRef(null)

const textInputProps={ 
  onSubmitEditing: () => tiRef.current?.focus() 
}

return(
<>
  <PhoneInput
    {...rest}
    textInputProps={textInputProps}
  />
 <TextInput
   ref={tiRef}
 />
</>
)

cloudorbush avatar Dec 10 '21 18:12 cloudorbush

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.

domoretrix avatar Dec 10 '21 19:12 domoretrix

@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.

domoretrix avatar Dec 10 '21 20:12 domoretrix

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!

lduran1997 avatar Jun 14 '23 09:06 lduran1997