react-native-masked-text: Error while trying to focus TextInputMask
I want to focus on TextInputMask, while user is clicking next button in the previous TextInput, when I’m trying to do it, I’m getting an error, how is possible to focus TextInputMask programmatically?
Here is my code:
<TextInput
style={styles.input}
placeholder='Last Name*'
ref={lastNameRef => this.lastNameRef = lastNameRef}
returnKeyType='next'
onSubmitEditing={() => this.phoneRef.focus()}
placeholderTextColor='#B1B1B1'
onChangeText={ text => this.onChangeLastName('lastName', text) }
/>
<TextInputMask
style={styles.input}
placeholder='Phone*'
ref={phoneRef => this.phoneRef = phoneRef}
returnKeyType='next'
type={'custom'}
value={this.state.phoneNumber}
options={{
mask: '(999) 999-9999'
}}
onChangeText={
text => this.onChangePhone('phoneNumber', text)
}
></TextInputMask>
About this issue
- Original URL
- State: open
- Created 5 years ago
- Comments: 24 (3 by maintainers)
Hey there, I’m also having trouble with maked input and refs. In my case I’m attaching the ref like this:
Logging the ref out I get this:
The same result happens if I just log the ref out like this:
No “focus” property is found in
current, but it’s found in_inputElement, so if I call itthis.valueInputRef.current._inputElement.focus();it does work.I’m using RN 0.58.5, masked-text 1.12.3;
Hi @Luckygirlllll could you check this sample?
Use
refInputinstead ofrefFor Typescript users:
let ref_name = useRef<TextInput>(null);let ref_cnpj = createRef<any>();<TextInputstyle={styles.input}placeholder="placeholder"autoCorrect={false}value={name}onChangeText={setName}ref={ref_name}returnKeyType='next'onSubmitEditing={() => ref_cnpj.current?._inputElement.focus()}/><TextInputMasktype={'cnpj'}style={styles.input}placeholder="CNPJ"autoCorrect={false}value={cnpj}onChangeText={setCnpj}ref={ref_cnpj}/>`Ref InputTextMask better way onSubmitEditing={() => phoneField.current.getElement().focus()}
Hello, I did like this:
react: 16.9.0 react-native: 0.61.2
The problem is that when I click Next, it does not focus on the next entry, could anyone help?
thanks @ammichael it works