3

I am facing this issue in iOS, did same thing on this link React Native TextInput that only accepts numeric characters but did not slove in iOS deivce

changes by setting state not reflecting in TextInput, below is my code:

constructor(props) {
super(props);
this.state = {
  enteredMobile: '',
};}

onChanged(text){
    this.setState({
            enteredMobile: text.replace(/[^0-9]/g, ''),
        });
  }

My Text Input

<TextInput
    placeholderTextColor="lightgrey"
    placeholder="Enter mobile no."
    keyboardType = 'numeric'
    maxLength={10}
    style={{height: 40,top:140, left :94,width:500, borderColor: 'white', borderWidth: 1}}
    onChangeText={(text) => this.onChanged(text)}
    value = {this.state.enteredMobile}
    />

You can see the updated one in the image below the table but its not updating TextInput itself.

enter image description here

Pankaj Bhardwaj
  • 2,081
  • 1
  • 17
  • 37

1 Answers1

0

Pankaj You have to code using ES6 JS in onChanged function because sometime it will not work in ES5 syntax.

Try this one

constructor(props) {
    super(props);
    this.state = {
        enteredMobile: '',
    };
}

onChanged = (text) => {
    this.setState({
            enteredMobile: text.replace(/[^0-9]/g, ''),
        });
  }

My Text Input

<TextInput
    placeholderTextColor="lightgrey"
    placeholder="Enter mobile no."
    keyboardType = 'numeric'
    maxLength={10}
    style={{height: 40,top:140, left :94,width:500, borderColor: 'white', borderWidth: 1}}
    onChangeText={(text) => this.onChanged(text)}
    value = {this.state.enteredMobile}
    />
Hardik Virani
  • 1,687
  • 7
  • 23
  • 36