Skip to content

[TextInput] When maxLength is full automatically focus next field #5617

@xcarpentier

Description

@xcarpentier

Hello RN awesome team !

I have an issue in my app with TextInput for a bank card number (error because user not type all number 16 digits).

So I would like to cut CB number on 4 TextInputs and focus automatically on next field after filled the 4 digits. (as already seen it in the web app)

But when I focused the next field, the current became empty, even if the state is correctly set.

Do you have an idea about how can I do that or is it impossible ?

ie. see the onChangeText on this example (exp date actually) :

<TextInput
    ref='card_exp_date_mm'
    style={[styles.inputTxt, {width: 30, flex: 0}]}
    value={this.state.cardExpDateMonth}
    keyboardType='numbers-and-punctuation'
    placeholder='MM'
    returnKeyType='next'
    clearTextOnFocus={false}
    autoCorrect={false}
    placeholderTextColor={Constants.placeholderTextColor}
    maxLength={2}
    enablesReturnKeyAutomatically={true}
    blurOnSubmit={false}
    onChangeText={text => {
      this.setState({cardExpDateMonth: text})
      //console.log('onChangeText', this.refs.card_exp_date_mm)
      if(text && text.length == 2){
        this.refs.card_exp_date_aa.focus();
      }
    }}
    onSubmitEditing={()=>this.refs.card_exp_date_aa.focus()}/>

Thanks by advance for your help.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Ran CommandsOne of our bots successfully processed a command.Resolution: LockedThis issue was locked by the bot.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions