Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trigger function to return a boolean on validation schema "sync" mode #715

Open
esivan-cloudinary opened this issue Sep 18, 2024 · 0 comments

Comments

@esivan-cloudinary
Copy link

esivan-cloudinary commented Sep 18, 2024

Is your feature request related to a problem? Please describe.

I'm managing a global state that keeps the form values of multiple forms (each with React Hook Form),
To validate all forms at once, I have to subscribe each form's 'trigger' function to an array, and execute all on click "Save"/"Update".
Since I don't have a reason to use asynchronous validation I use yupResolver(filtersSchema, undefined, { mode: 'sync' }) for synchronous validation. But the trigger function always returns a Promise.
This makes it a bit weird in the code (using Tanstack Query):

 const { mutate: createFlow, isLoading: isLoadingCreate } = useCreateFlow();

 const handleSave = async () => {
    const isFormValid = await validateForm();

    if (!isFormValid) {
      return;
    }

    createFlow({
      name: flowInitialName,
      graphInfo: { nodes: graphInfo.nodes.slice(0, -1), edges: graphInfo.edges.slice(0, -1) },
      values: formValues,
    });
  };

It's weird since I need to await for validateForm function but this shouldn't really be async.

Describe the solution you'd like

When { mode: 'sync' } is specified, trigger function should return a boolean (whether form is valid).

Describe alternatives you've considered

This solution suggested by @bluebill1049, but I haven't tried if it works sychronously.
#88 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant