Question about validation - Casting an input value to 'number'
See original GitHub issueI have an input that is supposed to contain a number. If I set the validation schema for this field to be yup.number().required()
, when I go to edit the field it complains, likely since it is treating the input value as a string. I see from the yup
docs that they have a cast
method, but I’m not sure how to have formik attempt to cast values before/during validation.
Is there something I’m missing? Am I meant to manually specify this cast in mapValuesToPayload
?
Issue Analytics
- State:
- Created 6 years ago
- Comments:12 (3 by maintainers)
Top Results From Across the Web
Python Tip: Validating user input as number (Integer)
To do so you can use the input() function: e.g. username=input("What is your username?"
Read more ><input type="number"> - HTML: HyperText Markup Language
<input> elements of type number are used to let the user enter a number. They include built-in validation to reject non-numerical entries.
Read more >Formik input value for a number becomes a string even after it ...
When the price is entered, any non-number is met with a warning. However, when I console log the the value passed to the...
Read more >Check user Input is a Number or String in Python - PYnative
Solution: In such a situation, We need to convert user input explicitly to integer and float to check if it's a number. If...
Read more >Why the number input is the worst input - Stack Overflow Blog
When the number input contains an invalid value and you retrieve the value, you get a blank string. · Valid numbers include more...
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
input
typenumber
works, but is not available forselect
and, in general, for custom inputsI’d recommend doing something similar to @davidspiess above, except you can create a composable callback like this:
FYI in v2 there are possible plans for an
onParse
-like API. Hopefully that will make things easier #1525