In react native, I’m having trouble focussing the TextInput field.
When the user submits the Text field with a blank then it will focus on that TextInput.
How can I Do it?
<TextInput style={styles.inputs} placeholder="Enter Mobile No" placeholderTextColor="#8e8e8e" autoCapitalize='none' onChangeText={mobileNo => this.onChangedMobile(mobileNo)} value={this.state.mobileNo} underlineColorAndroid='transparent' keyboardType={'numeric'} />
First, assign the TextInput field to a ref like this
<TextInput style={styles.inputs} ref={mobileNo => (this.mobileNo = mobileNo)} />
After that, you can programmatically focus it by running focus() on it.
For example:
if(this.state.mobileNo=='' || this.state.mobileNo == null){ this.mobileNo.focus(); }
Question and answer is powered by AnsPress.io