question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

iOS allows too many characters

See original GitHub issue

The following custom definition permits too many characters on iOS. Android correctly forbids the user from entering more than the specified mask. In the following example, Android restricts the text input from having more than 1 digit, but iOS does not.

 <TextInputMask
            type='custom'
            options={{mask: '9'}}
            value={this.state.inputVal}
            keyboardType='numeric'
            onChangeText={val => val.length <= 1 && this.setState({ inputVal: val })}
          />

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
zaguiinicommented, Apr 26, 2018

Hey, I’ve found a “workaround” for now: just define maxLength on your TextInput.

That’s the “solution” while there isn’t an official bugfix… Example:

If you define the credit-card mask, just define the maxLength of your input to 19, so it will cover the 16 digits of the credit card plus the 3 spaces. 👍

2reactions
bhrottcommented, Apr 22, 2018

Hi,

After a long investigation, I realize it can be a bug in react-native.

I tried with both TextInputMask and default TextInput. The state remains correct but it does not update current text input value O.o.

This is the code:

export default class App extends React.Component {
  state = {
    inputVal: ''
  }

  _updateVal(val) {
    if (val.length <= 1) {
      this.setState({ inputVal: val }, () => {
        console.log(this.state)
      })
    }
  }

  render() {
    return (
      <View style={styles.container}>
        <Text>TextInputMask: </Text>

        <TextInputMask
          type='custom'
          options={{ mask: '9' }}
          value={this.state.inputVal}
          keyboardType='numeric'
          onChangeText={this._updateVal.bind(this)}
          style={styles.input}
        />

        <Text>Default TextInput: </Text>
        <TextInput
          value={this.state.inputVal}
          keyboardType='numeric'
          onChangeText={this._updateVal.bind(this)}
          style={styles.input}
        />
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
  input: {
    borderWidth: 1,
    borderColor: 'red',
    height: 50,
    width: '90%'
  }
});

And take a look when we input some values into input: img_2647

Now, take a look at the console.log to see the state: image

This is absolutely bizarre and the same happen if we input values on MaskedTextInput. I will open an issue on React-Native’s repository.

Thanks for reporting.

Read more comments on GitHub >

github_iconTop Results From Across the Web

iPhone: How to enable character counter in the Messages app
iPhone: How to enable character counter in the Messages app. Fire up Settings > Messages. Scroll down until you see the SMS/MMS portion....
Read more >
Limit number of characters in uitextview - ios - Stack Overflow
suppose that I have reached the limit of 140 characters so that the method will give me false and the user can not...
Read more >
iOS allows too many characters · Issue #68 - GitHub
The following custom definition permits too many characters on iOS. Android correctly forbids the user from entering more than the specified ...
Read more >
How to Turn on Character Count on an iPhone in 5 Steps
How to turn on character count on your iPhone. 1. Open your iPhone's Settings app. 2. Scroll and select the "Messages" tab. You...
Read more >
The iPhone Text Character Limit - Small Business - Chron.com
As long as the person you're texting has an iPhone, iPad or other iOS device with an active data connection, the operating system's...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found