Smart Form Component and validate function
See original GitHub issueFirst of all - I would like to congratulate you on a great library and docs!
I have implemented smart forms similar to these: https://codesandbox.io/s/react-hook-form-smart-form-component-eqb3n (Note this codesandbox link from your docs does not actually use smartform components or even work)
As we pass in a custom validate function to something like <Input/>
we need access to the rest of the values on the form. For example, if I were to build a password changing screen - where the two passwords would have to match - with smart form components, the validate function would need access to things from the form. It would need the values from the form. It might want the touched values, etc.
What I wanted to propose was to add a 2nd parameter to the validate function. At a minimum the 2nd parameter would be getValues
function - that a validator function could call if it needed them. At max, the 2nd parameter would be an object that contained '‘all’ of the functions from UseForm() call. That might be overkill, but we do need the getValues() function - and I could see people wanting ‘touched’. (no since in comparing and showing an error for passwords not matching until both fields are touched.
Thoughts on this idea or another suggestion?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:24 (15 by maintainers)
@bluebill1049 thanks a lot now it works for me ❤️
@tafelito you are doing correctly 😃 using
getValues
is right 👍