Empty input type=number results in NaN
See original GitHub issueI’m using Formik with Yup Schema validation.
I have an input field of type “number”. If I enter a value and empty the field this results in a NaN
. This behavior might be as expected. For that I added a transform function to my schema like that:
yup
.number()
.transform(value => {
console.log(value, Number.isNaN(value) ? 0 : value
return Number.isNaN(value) ? 0 : value
})
Should it respect the transform function? Or is the schema actually only be used for validation, not for “cleaning” the data? If so, is there a way how to solve that? Maybe I’m missing something. Of course, I can check the value before attaching it to the input field. But the value in the global values object stays the same.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Differentiate between NaN input and empty input with an Input ...
The problem with this is that I want to differentiate between the user entering an empty string (""), and the user entering a...
Read more >NaN - JavaScript - MDN Web Docs
The global NaN property is a value representing Not-A-Number. ... Math operation where the result is not a real number (e.g. Math.sqrt(-1) ) ......
Read more >Can I prevent "NaN" from appearing in numerical entry?
The logic is based on a boolean "isNaN" flag variable that gets initialized to true, and is then reset to false if the...
Read more >Create array of all NaN values - MATLAB NaN - MathWorks
X = NaN returns the scalar representation of "not a number". Operations return NaN when they have undefined numeric results, such as 0/0...
Read more >Convert NaN to 0 using JavaScript | bobbyhadz
Use the logical or operator to convert `NaN` to `0`, e.g. `const result = val || 0;`. ... undefined , false , 0...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
try to use setFieldValue
I am having the same issue, has this been fixed or is there some recommended way of dealing with this?