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 text is undefined on blur in android #20771

Closed
3 tasks
dmoss18 opened this issue Aug 21, 2018 · 5 comments
Closed
3 tasks

TextInput text is undefined on blur in android #20771

dmoss18 opened this issue Aug 21, 2018 · 5 comments
Labels
Component: TextInput Related to the TextInput component. Platform: Android Android applications. Resolution: Locked This issue was locked by the bot.

Comments

@dmoss18
Copy link

dmoss18 commented Aug 21, 2018

Environment

Environment:
OS: macOS High Sierra 10.13.6
Node: 10.3.0
Yarn: 1.9.2
npm: 6.1.0
Watchman: 4.9.0
Xcode: Xcode 9.4.1 Build version 9F2000
Android Studio: 3.1 AI-173.4720617

Packages: (wanted => installed)
react: ^16.4.1 => 16.4.1
react-native: 0.55.4 => 0.55.4

Description

I have an onBlur handler for a TextInput that should pass in the text via the nativeEvent. However, the text is always undefined on android. It works on iOS.

handleBlur = (event: NativeSyntheticEvent<TextInputFocusEventData>) => {
  console.log(event.nativeEvent.text)
}

render() {
  return (
    <TextInput onBlur={this.handleBlur} value="Test" />
  )
}

Reproducible Demo

https://snack.expo.io/By6uT3F87

@dmoss18
Copy link
Author

dmoss18 commented Aug 21, 2018

This issue was originally reported here but they didn't really provide examples/follow the template.

@dmoss18
Copy link
Author

dmoss18 commented Aug 21, 2018

I found a workaround here

onEndEditing instead of onBlur works exactly the same and provides the text

@react-native-bot react-native-bot added Platform: Android Android applications. Component: TextInput Related to the TextInput component. ⏪Old Version labels Aug 21, 2018
@react-native-bot
Copy link
Collaborator

Can you reproduce the issue on the latest release, v0.56?

@dulmandakh
Copy link
Contributor

dulmandakh commented Aug 29, 2018

IMHO, it's better to use onChangeText and store the text in the state, then access text from state

handleBlur = () => {
  // access this.state.text
}

handleChangeText = text => {
  this.setState({ text })
}

render() {
  return (
    <TextInput onChangeText={this.handleChangeText} value={this.state.text} />
  )
}

@Elijen
Copy link

Elijen commented Mar 1, 2019

@dulmandakh Why did you close the issue though? The bug should still be fixed. Can we reopen?

I have reproduced it in v0.57.1 (Expo v32).

//cc @hramos

@facebook facebook locked as resolved and limited conversation to collaborators Aug 29, 2019
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Aug 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Component: TextInput Related to the TextInput component. Platform: Android Android applications. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

4 participants