Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TextInput won't clear onKeyPress #9960

Closed
bsiddiqui opened this issue Sep 17, 2016 · 5 comments
Closed

TextInput won't clear onKeyPress #9960

bsiddiqui opened this issue Sep 17, 2016 · 5 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@bsiddiqui
Copy link

I have a multiline TextInput that I want to clear when the return key is pressed.

I have been able to clear the input with this.refs.input.clear() and this.refs.input.setNativeProps({ text: '' }) but these don't work when using them onKeyPress

This does not work

onKeyPress={event => if (event.nativeEvent.key === 'Enter') this.refs.input.clear()

I would expect that it would clear the input

Using RN 0.31.0

@bsiddiqui bsiddiqui changed the title TextInput won't clear TextInput won't clear onKeyPress Sep 17, 2016
@antoxi4
Copy link

antoxi4 commented Sep 18, 2016

Where you use this code? Android or IOS? onKeyPress work only on IOS)

@bsiddiqui
Copy link
Author

@antoxi4 I'm using on iOS

@lacker
Copy link
Contributor

lacker commented Dec 15, 2016

I suggest using controlled components so that you can just clear out the data directly, rather than using refs and an uncontrolled form here.

@lacker lacker closed this as completed Dec 15, 2016
@Woodswu
Copy link

Woodswu commented Jan 17, 2017

I also have the same problem

@Woodswu
Copy link

Woodswu commented Jan 17, 2017

you can like this

this is my demo

first set blurOnSubmit={true}

second:
onSubmitEditing={()=>{this.refs.input.clear()}}

@facebook facebook locked as resolved and limited conversation to collaborators Jul 19, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

5 participants