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

Changing a number field from 11 to 1 will fail to render the new value #2157

Open
captain-geek opened this issue Dec 3, 2020 · 7 comments
Open
Labels
bug core help wanted p1 Important to fix soon

Comments

@captain-geek
Copy link

In our project we were using a form that contained a number input, we noticed that if we changed the form value from 11 to 1 the field would continue to show 11 when the formData held 1

The pattern was confirmed with 420 and 20, or 17 and 7, 1234 and 234 ...

The error lies in the following line of code:

const re = new RegExp(`${value}`.replace(".", "\\.") + "\\.?0*$");

If you change it to:

const re = new RegExp(`^${value}`.replace(".", "\\.") + "\\.?0*$");

the field will render correctly when the value changes

(note the "^" added to the beginning of the regex so that it has to match the full string value, not just the right side of the value)

jeffothy added a commit to jeffothy/react-jsonschema-form that referenced this issue Jan 16, 2021
…eam#2157)

Use a ^ to ensure regex matches the entire new value and not just the
end of the value.

Normalize the cache value with a leading zero when it starts with a
decimal character as is done in handleChange.

Co-authored-by: Landon Bradshaw <landon.bradshaw@gmail.com>
jeffothy added a commit to jeffothy/react-jsonschema-form that referenced this issue Feb 3, 2021
…eam#2157)

Use a ^ to ensure regex matches the entire new value and not just the
end of the value.

Normalize the cache value with a leading zero when it starts with a
decimal character as is done in handleChange.

Co-authored-by: Landon Bradshaw <landon.bradshaw@gmail.com>
jeffothy added a commit to jeffothy/react-jsonschema-form that referenced this issue Mar 4, 2021
…eam#2157)

Use a ^ to ensure regex matches the entire new value and not just the
end of the value.

Co-authored-by: Landon Bradshaw <landon.bradshaw@gmail.com>
jeffothy added a commit to jeffothy/react-jsonschema-form that referenced this issue Mar 8, 2021
…eam#2157)

Use a ^ to ensure regex matches the entire new value and not just the
end of the value.

Normalize the cache value with a leading zero when it starts with a
decimal character as is done in handleChange.

Co-authored-by: Landon Bradshaw <landon.bradshaw@gmail.com>
jeffothy added a commit to jeffothy/react-jsonschema-form that referenced this issue Mar 8, 2021
…eam#2157)

Use a ^ to ensure regex matches the entire new value and not just the
end of the value.

Normalize the cache value with a leading zero when it starts with a
decimal character as is done in handleChange.

Co-authored-by: Landon Bradshaw <landon.bradshaw@gmail.com>
liaody pushed a commit to ceptontech/react-jsonschema-form that referenced this issue May 24, 2021
…eam#2157)

Use a ^ to ensure regex matches the entire new value and not just the
end of the value.

Normalize the cache value with a leading zero when it starts with a
decimal character as is done in handleChange.

Co-authored-by: Landon Bradshaw <landon.bradshaw@gmail.com>
@leology
Copy link

leology commented Mar 16, 2023

@jacqueswho @epicfaace - I notice that the suggested Regex by @captain-geek , has not been merged to main branch. Our team is using this library too, and we noticed that when let's say text field is given a number '10', any number that starts with '10' and ends with '10' will not reset when we do router.replace (reset implying that the field returns to its original/default value).

I know, I've reported this in a vague way, but the question is, have this solution been merged to master/main ?

@jacqueswho
Copy link
Contributor

@leology will discuss with the team on Friday, hopefully get this in on the next release, since its a small change

@heath-freenome heath-freenome added the p1 Important to fix soon label Mar 24, 2023
@heath-freenome
Copy link
Member

So after trying it with 5.x it seems that only the 11 -> 1 is still problematic. The others are working

@maximecote57
Copy link

Also getting this issue on the project I'm working on. The issue is easily reproducible in the playground.

Any updates on this? Would appreciate if a fix could be merged.

Thank you!

@heath-freenome
Copy link
Member

@maximecote57 Given that the main maintainers of the project are volunteers who generally only have a few hours a week to focus on things, most of the corner-case issues aren't generally a high priority. Would you be willing to provide the fix in a PR? I believe that the solution provided above may work as is. Thanks for understanding

@maximecote57
Copy link

Unfortunately the above solution makes some tests break so I'm not sure it's the correct solution. I'll try to find some time to investigate later this week. Thank you!

@heath-freenome
Copy link
Member

@maximecote57 if you have any questions, feel free to ask them here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug core help wanted p1 Important to fix soon
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants