1

I have a <TextInput />. I am trying to simulate key press event on "submit" button where I added it below the TextInput. Here code:

<TextInput style={styles.textInput} onSubmitEditing={event => onSubmitEditButton(event.nativeEvent.text)} /> <TouchableHighlight onPress={"HERE I AM TRYING TO SIMULATE ENTER-KEY PRESS IN ORDER TO TRIGGER OnSubmitEditing EVENT"} style={{position:"absolute", top:50}}> <Text>Submit</Text> </TouchableHighlight 
1

1 Answer 1

0

If you simply want onSubmitEditing to do the same thing on a button press, then just call onSubmitEditing in onPress of your button. But this would require storing the text within an input externally:

const [text, setText] = useState('') const onSubmit = ()=>{ // do stuff with text in textinput console.log(text) Keyboard.dismiss() } return ( <TextInput style={styles.textInput} onChangeText={setText} onSubmitEditing={onSubmit} /> <TouchableHighlight onPress={onSubmit} style={{position:"absolute", top:50}} > <Text>Submit</Text> </TouchableHighlight> ) 
Sign up to request clarification or add additional context in comments.

1 Comment

But I don't want to use setState hook at onChangeText because it is being called at every key press. Therefore I tried to simulate "Enter" key press and use only onSubmitEditing

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.