react-jsonschema-form icon indicating copy to clipboard operation
react-jsonschema-form copied to clipboard

Issue when resetting certain numbers with a default value

Open ayush-shta opened this issue 1 year ago • 2 comments

Prerequisites

What theme are you using?

core

Version

5.x

Current Behavior

Numbers not resetting when the number entered in that field ends with the default value provided for that field in the schema

Expected Behavior

Values should reset as expected and should not depend upon what the default value is

Steps To Reproduce

I tried to replicate this issue in the playground. Link

  1. Lets say I have a schema including one of the property to be like the one below. Here the default value of this field is 1.
  "number": {
      "title": "Number",
      "type": "number",
      "default": 1
    },
  1. Now I type in the value for this filed as any number ending with the default value (for example, 11, 231, 0.1, 1.1, 2.1, 0.0001)
  2. After that, lets click the button to reset the form
  3. The value for that field does not reset
  4. However if we type in any other number that does not end with the default value it will reset as expected

Environment

- OS:
- Node:
- npm:

Anything else?

No response

ayush-shta avatar May 25 '24 06:05 ayush-shta

Looks like a bug in the regular expression in NumberField: https://github.com/rjsf-team/react-jsonschema-form/blob/ec932db942dd046640303056c89e3501b16ec469/packages/core/src/components/fields/NumberField.tsx#L74

The update is reverted because the new value matches the regular expression, when it should not match.

nickgros avatar Jun 14 '24 17:06 nickgros

Proposed fix here: https://github.com/rjsf-team/react-jsonschema-form/pull/4220

nickgros avatar Jun 14 '24 18:06 nickgros

Fixed by #4420

heath-freenome avatar Jul 05 '24 19:07 heath-freenome