Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TextInput] How do you implement maxLength for TextInput? #1945

Closed
leonlxli opened this issue Jul 10, 2015 · 9 comments
Closed

[TextInput] How do you implement maxLength for TextInput? #1945

leonlxli opened this issue Jul 10, 2015 · 9 comments
Labels
Good first issue Interested in collaborating? Take a stab at fixing one of these issues. Resolution: Locked This issue was locked by the bot.

Comments

@leonlxli
Copy link

Is there a way for you to limit the number of characters that you can enter into a textInput similar to how maxLength works?

@brentvatne brentvatne changed the title How do you implement maxLength for TextInput? [TextInput] How do you implement maxLength for TextInput? Jul 10, 2015
@brentkirkland
Copy link

What if you checked onTextChange if the text was <= the desired length of characters?

@leonlxli
Copy link
Author

onChangeText still makes the change. I want to make it so that if the user is not allowed to enter in more than the maxLength. When I used onChangeText, it still changes the input

@brentvatne
Copy link
Collaborator

We would need to handle this on the native side, eg: http://stackoverflow.com/questions/2523501/set-uitextfield-maximum-length

Overall, TextInput needs a lot of work. I know @sahrens is working on some improvements now but any community help on this one is very much appreciated!

What we would need to do:

  • Look at the maxLength spec for web and ensure we understand all of its behaviours
    • This should be pretty easy - adding keystrokes to the text field contents once the length has reached. Something to consider though - do we provide a hook for the JS side to respond to press events after we have exceeded this? This line of thinking is necessary. We'll need to consider common use cases for maxlength and ensure we can handle those.
  • Add a prop to TextInput with the same, make the backing logic on the ObjC side
  • Add an example to UIExplorer

@brentvatne brentvatne added Community Responsibility Good first issue Interested in collaborating? Take a stab at fixing one of these issues. labels Jul 21, 2015
@dsibiski
Copy link
Contributor

I implemented shouldChangeCharactersInRange in this PR: #2082 for issue #1882

These two definitely overlap. Would be nice to see a convergence of ideas here.

@sahrens
Copy link
Contributor

sahrens commented Jul 22, 2015

This and several fixes landed internally and should sync out this week.

On Jul 22, 2015, at 1:40 AM, Dave Sibiski [email protected] wrote:

I implemented shouldChangeCharactersInRange in this PR: #2082 for issue #1882

These two definitely overlap. Would be nice to see a convergence of ideas here.


Reply to this email directly or view it on GitHub.

@brentvatne
Copy link
Collaborator

@sahrens - awesome, super excited! thanks!

@browniefed
Copy link
Contributor

@brentvatne this landed into master so this can probably be closed?

@monyxie
Copy link

monyxie commented Aug 3, 2015

The current implementation doesn't seem to work with Chinese keyboard.
textinput maxlength issue

@ide
Copy link
Contributor

ide commented Aug 15, 2015

Closing this since maxLength has been implemented. Will open a new issue for the problem with Chinese characters.

@ide ide closed this as completed Aug 15, 2015
@facebook facebook locked as resolved and limited conversation to collaborators Jul 22, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 22, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Good first issue Interested in collaborating? Take a stab at fixing one of these issues. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

9 participants