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

NumberInput: add option to allow only positive integers #206

Closed

Conversation

jrcastro2
Copy link
Contributor

required,
disabled,
type,
positiveIntegerOnly,
Copy link
Contributor

@kpsherva kpsherva Sep 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is bypassing validation (backend or frontend) in an unorthodox way, without providing any feedback to the user on incorrect input. I think it might be confusing for the user
why not using the min html attribute ?
<input type="number" min="0">
or
<input type="number" step="1" pattern="\d+"> this one should give feedback when you try to type -
this approach can be used without adding a new prop the html attributes should be automatically added by react to the output element

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand the first part, the user gets the same feedback as when he tries to type any letter, when he types it, it will not appear in the field.
I agree that we should align the validations between the backend and frontend but it's not correct at the moment either, as in the frontend it's allowed to introduce +- sign and when doing this it will not save the number (although it's displayed in the UI). Here an example of this:

Peek.2023-09-12.18-06.mp4

By doing this change it actually aligns a bit more with the backend validation.

I agree that ideally we also want to remove the + and - sign from the backend validation, but I also think we could tackle that in the future.

I also tried your suggestions without any luck, maybe I am doing something wrong:
Screenshot from 2023-09-12 18-08-39

@jrcastro2
Copy link
Contributor Author

This is "not needed" anymore, however there is an issue with the InputNumber where you can type +-123 and will be evaluated as a string and since the input type is number it will not be submitted but it will appear filled in the field.

@jrcastro2 jrcastro2 closed this Sep 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants