guillotinaweb / ngx-schema-form

HTML form generation based on JSON Schema
MIT License
483 stars 173 forks source link

Large number input fields behaving oddly #471

Closed ymeunierIGT closed 1 year ago

ymeunierIGT commented 1 year ago

I noticed a problem with users entering a large value into our custom number input widget. Once you entered more than 16 digits the widget starts to display odd values, until it resets itself to a blank input. This can also be reproduced using the demo page available on the main page, and enter in more than 16 digits into the zip input field.

In general this isn't really a problem for us, we tweaked our custom widget to limit to 16 digits as this is more than we currently need in all our use cases, but is this expected behavior?

ebrehault commented 1 year ago

I assume it is because JavaScript cannot handle integers larger than 2^53.

I think you might be using an integer value for a wrong reason. Typically, a ZIP code is not really an integer. Semantically, it is more a string value made of numbers.

So maybe you could use a string value with a pattern checking it contains only numbers.

ymeunierIGT commented 1 year ago

Thanks @ebrehault, that explains the digit limitation, forgot JS wasn't using the entire 64bit.

The mention of the zip field, was only to show the behaviors since it was a plain number widget to test on. In our cases they are meant as numbers, and do have a max set in their schema, but this does not stop a user from entering more digits.

I'll close with this comment, custom widget seems like the way to go if we want to stop input from taking more than 16 chars/digits