0

I'm getting undefined is not a function (evaluating '_this2._password.focus()') when trying to focus on the next field:

<View style={{ height: h * .13, width: w }}>
   <Kohana style={[styles.input, { backgroundColor: '#f9f5ed' }]}
           label={'Email'}
           onChangeText={(email) => this.email = email}
           iconClass={MaterialsIcon}
           iconName={'email'}
           iconColor={'#ddd'}
           iconColor={'#f4d29a'}
           keyboardType={'email-address'}
           labelStyle={[styles.inputLabel, { color: '#91627b' }]}
           inputStyle={[styles.inputInput, { color: '#91627b' }]}
           blurOnSubmit={false}
           returnKeyType={"next"}
           onSubmitEditing={(e) => {this._password.focus()}} />
</View>
<View style={{ height: h * .13, width: w }}>
   <Kohana
           style={[styles.input, { backgroundColor: '#f9f5ed' }]}
           ref={(ref) => this._password = ref}
           label={'Password'}
           onChangeText={(password) => this.password = password}
           secureTextEntry={true}
           iconClass={MaterialsIcon}
           iconName={'lock'}
           iconColor={'#ddd'}
           iconColor={'#f4d29a'}
           blurOnSubmit={true}
           labelStyle={[styles.inputLabel, { color: '#91627b' }]}
           inputStyle={[styles.inputInput, { color: '#91627b' }]}/>
</View>

I've tried other solutions, the one when you make the ref a string, and calling it like this.refs._refName.focus() and the one from Facebook, where you make the refs consecutive integers - [this][1], but none of them work.

Bojan B
  • 2,091
  • 4
  • 18
  • 26
Marko Mijailovic
  • 421
  • 1
  • 4
  • 17

1 Answers1

1

Focus is a method of TextInput component. However, you can add a custom focus method in your Kohana component, and call the focus of TextInput present in your component. You will have to add a reference to the TextInput to do so.

See my answer here : undefined exception while calling focus method on TextInput ref

Community
  • 1
  • 1
Saleel
  • 889
  • 5
  • 10
  • Kohana is a component from [react-native-textinput-effects](https://github.com/halilb/react-native-textinput-effects), it accepts props and methods from TextInput (notice the keyboardType, blurOnSubmit, etc.) Could you please take a look at [this](http://pastebin.com/iH2kzNT9), I don't see where I would add the focus method. – Marko Mijailovic Oct 15 '16 at 10:42
  • 1
    I have checked the code. It do pass all the props it gets to the underlying TextInput component. This is why you can use the build in TextInput props (but not methods). Check [this updated code](http://pastebin.com/GGFbzPQw) with focus method added. – Saleel Oct 16 '16 at 04:58