React-native: TextInput onEndEditing doesn't work

Created on 28 Apr 2016  路  11Comments  路  Source: facebook/react-native

I wonder why onEndEditing on TextInput doesn't work. Following code works well on onChangeText, but not on onEndEditing:

<TextInput ref="title"
   placeholder="Type title here"
   style={styles.title}
   onEndEditing={(text) => console.log(text)}
   onChangeText={(text) => console.log(text)}
/>

my env:

  • Ubuntu 14.04
  • Android 4.2.2
  • React Native 0.24
Locked

Most helpful comment

It seems onEndEditing does not get the value of text, but just the event.

In the docs:

onChangeText function 

Callback that is called when the text input's text changes. **Changed text is passed as an argument to the callback handler.**

Whereas:

onEndEditing function 

Callback that is called when text input ends.

And if you log your text you get a SyntheticEvent.

What you were looking for was a onEndEditingText that unfortunately doesn't seem to exist. It would be great to have that, as that was also the behaviour that I expected.

All 11 comments

Can you please include an example on rnplay.org?

please take a look at this example

onEndEditing does nothing on android

It looks like it's not onEndEditing that is the problem...since it does work when you manually blur the textInput like in my example here: https://rnplay.org/apps/Wr_mWw

The problem seems to be that the "Enter" button, or the "Dismiss Keyboard" button, doesn't properly blur the textInput. You can see that when you dismiss the keyboard that textInput stays focused.

It seems like this issue: https://github.com/facebook/react-native/issues/7047 is more appropriate for what you are experiencing. It seems like perhaps that is expected behavior for Android. Perhaps @satya164 can shed some light on that...

Thank you for pointing it out. Just curious, are you experiencing the same problem on real android device without manually blur the TextInput ?

@iwanjunaid Yes, I just ran the rnplay example on my real device and it has the exact same behavior.

It seems onEndEditing does not get the value of text, but just the event.

In the docs:

onChangeText function 

Callback that is called when the text input's text changes. **Changed text is passed as an argument to the callback handler.**

Whereas:

onEndEditing function 

Callback that is called when text input ends.

And if you log your text you get a SyntheticEvent.

What you were looking for was a onEndEditingText that unfortunately doesn't seem to exist. It would be great to have that, as that was also the behaviour that I expected.

It sounds like this is more of a feature request than a bug at this point so I am going to close this issue. I encourage you to file feature requests on product pains though, or to send a pull request adding this event, because it does seem to be useful. If you do have some of this behavior that is a bug then I encourage you to open a new issue.

In what way does onEndEditing differ from onBlur (was looking to implement on web)?

Thanks!

Was this page helpful?
0 / 5 - 0 ratings