jaredpalmer / formik

Build forms in React, without the tears 😭
https://formik.org
Apache License 2.0
33.71k stars 2.77k forks source link

passing all values as the second parameter when calling Field's validate #3874

Open myNameIsDu opened 10 months ago

myNameIsDu commented 10 months ago

Feature request

passing all values as the second parameter when calling Field's validate

Current Behavior

just passes the current value as the first parameter

Desired Behavior

passing all values as the second parameter when calling Field's validate

Suggested Solution

passing all values as the second parameter when calling Field's validate

Who does this impact? Who is this for?

Describe alternatives you've considered

I have tried many alternative solutions, but I haven't found a suitable one.

Additional context

In the context of my application, there's a dynamic form, For example, it's a radio group. When I select the 'A' option, it triggers the rendering of an additional input or other components. Once rendered, this component is automatically registered and set as 'required'. On the other hand, if I opt for a selection other than 'A', different fields and components get registered. So that's the reason why I'm using Field's validate, I don't have to operate the huge schema, The Field'validae comes with automatic registration and logout

Here's the smallest reproducible example: https://stackblitz.com/edit/stackblitz-starters-pxyrgo?file=src%2FApp.tsx. To reproduce the issue, follow these steps:

  1. Click the 'Add' button.
  2. Enter "1" into the second input.
  3. Check the console.

You'll notice that the values in the validate function are stale.

Finally, I'd like to thank you for your outstanding work in creating this invaluable form library. Regarding this issue, if you agree to add this feature, I'm more than willing to implement it