Supply touched object to validation method
See original GitHub issueFeature
Current Behavior
Currently the validation method takes in as parameters the values
from the form and props
. In my current situation, I have to show an error on input A when input B has been interacted with but only if input A has been touched. Inside the validation method, there is no way to grab the information of the touched values and so it makes this type of validation really difficult.
Desired Behavior
Have access to the touched
object in the validation method.
Suggested Solutions
Pass the touched object to the validation method.
- Formik Version: 0.11.11
- OS: Windows 10
- Node Version: 8.9.4
- Package Manager and version: npm 5.6.0
Opinions?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:5
- Comments:11 (3 by maintainers)
Top Results From Across the Web
Basic Errors - Formik for Beginners
You supply it with a name . When that fields contains an error and the field has been touched. Then it will display...
Read more >React form validation solutions: An ultimate roundup
This roundup is a comprehensive look at some of the most popular solutions for form management and validation in React.
Read more >useForm - trigger - Simple React forms validation
Manually triggers form or input validation. This method is also useful when you have dependant validation (input validation depends on another input's ...
Read more >how to write validation in sencha touch / ext js model
Errors object return by the validate method of the model. So we can do something like: var record = Ext.create('Ext.data.
Read more >withFormik() | Formik
Your form submission handler. It is passed your forms values and the "FormikBag", which includes an object containing a subset of the injected...
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 Free
Top 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
Hiya,
There are definitely situations where this would be useful, for example:
I have a form with two fields,
monthlyAmount
andyearlyAmount
. A user only needs to fill in one of the two.If the user focuses on
monthlyAmount
, tabs off, and focusesyearlyAmount
, and tabs off (without filling in any value in either) an error needs to be displayed in both. (monthlyAmount
- Monthly, or, andyearlyAmount
- Yearly amount required). This means I need to wait until both are touched before validating either.However, if the user focuses on
monthlyAmount
, fills in an incorrect value, and tabs off, an error needs to be displayed immediately (monthylAmount
- Enter a monthly value less than 100).Here is a sample of the code that will work if I am supplied with
touched
in my validation method.form.js
component.jsx
Maybe you can suggest a clean solution without using
touched
?Right so why can’t you just do something like
{touched.fieldA && touched.fieldB && errors.fieldB}
?