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

Add maxLength prop to inputs #187

Closed
carlosriveros opened this issue Aug 20, 2019 · 4 comments
Closed

Add maxLength prop to inputs #187

carlosriveros opened this issue Aug 20, 2019 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@carlosriveros
Copy link

Currently, even if the format is 'M/d/yyy' you can enter any length input for month, day, or year.

image

I have tried using JavaScript to limit the amount of character that can be entered as input, but it does not work.

document.querySelectorAll('.react-date-picker__inputGroup__year').forEach(el => { el.setAttribute('maxlength', 4) el.setAttribute('max', 9999) })

Is there a suggested way to do this?

Otherwise, can we add this feature?

@carlosriveros
Copy link
Author

unfortunately number type inputs don't accept the maxlength property.
The fix will have to be something like https://stackoverflow.com/questions/9841363/how-to-restrict-number-of-characters-that-can-be-entered-in-html5-number-input-f

@wojtekmaj wojtekmaj added the enhancement New feature or request label Aug 27, 2019
@wojtekmaj
Copy link
Owner

max is actually already set, but this is only for input validation. Max length is a good idea; native picker has this.

@wojtekmaj wojtekmaj changed the title Allow props maxlength and max Add maxlength prop to inputs Aug 27, 2019
@wojtekmaj wojtekmaj self-assigned this Aug 27, 2019
@wojtekmaj wojtekmaj changed the title Add maxlength prop to inputs Add maxLength prop to inputs Dec 8, 2019
@karthibalu98
Copy link

I am able to type more than 4 digit even after adding el.setAttribute('maxlength', 4).
Can you please help me to resolve the same.

@wojtekmaj
Copy link
Owner

With 0f2923a it will no longer be possible to enter values that are longer than max. So, by default, you should be able to enter e.g. year as long as 6 digits (Sep 13 275760 is maximum allowable date in JavaScript), but setting maxDate to something lower than that, e.g. new Date(9999, 12, 31) will disable users from writing more than 4 digits in year input.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants