nextui icon indicating copy to clipboard operation
nextui copied to clipboard

[BUG] - Form Allows Submission with Decimal in Number Input

Open znadir opened this issue 1 year ago • 5 comments

HeroUI Version

2.4.17

Describe the bug

When the number input contains an invalid value, such as a decimal number, the form still allows submission instead of blocking it as expected.

Your Example Website or App

https://github.com/znadir/bug-number-input

Steps to Reproduce the Bug or Issue

  1. Enter a decimal number in the input
  2. Submit the form by clicking on the button. do not press enter
  3. Watch the form being submitted even when there is an error

Expected behavior

The number input allows decimal values. The form should not be submitted when clicking on submit button if the input contains a decimal.

Screenshots or Videos

Image

Operating System Version

Windows

Browser

Firefox

znadir avatar Jun 05 '25 15:06 znadir

Just took a deeper look. I won't suggest to use Input with number type since Input is using text field hook which does not handle numeric case well. For your case, any reason you are not using NumberInput? If the numeric input requires whole number, you can do the following with NumberInput.

<NumberInput label='Enter a number' formatOptions={{
  maximumFractionDigits: 0
}} />

see https://www.heroui.com/docs/components/number-input

wingkwong avatar Jun 06 '25 13:06 wingkwong

I didn't know about it thanks. That would still be nice to get the issue fixed

znadir avatar Jun 06 '25 17:06 znadir

@wingkwong I think this can be closed right..?

jassBawa avatar Jun 06 '25 18:06 jassBawa

@jassBawa I'll update the typing a bit. Ideally we would like to separate Input and NumberInput.

wingkwong avatar Jun 07 '25 01:06 wingkwong