question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[FEAT] Have a clear way to propagate errors to forms

See original GitHub issue

I want to be able to provide the form component with the server returned errors in an easy manner

Describe the solution you’d like I’d imagine a parseErrors, transformErrors, processErrors method I could supply useForm that would receive the response object and would use the return value (probably an object of structure `{ fieldName: errorText[]} mapping) to set the form errors,

Describe alternatives you’ve considered currently doing it manually using onMutationError, and handling the error object on my own. which doesn’t allow me to use setError since it’s a return value of useForm

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
mayank-meragicommented, Jul 19, 2022

@banuni I use something like this

export const useForm = <
  TData extends BaseRecord = BaseRecord,
  TError extends HttpError = HttpError,
  TVariables = {},>(
  props: UseFormProps<TData, TError, TVariables> = {},
): UseFormReturnType<TData, TError, TVariables> => {
  const useFormProps = useFormAntd<TData, TError, TVariables>(props)
  useEffect(
    () => {
      if (useFormProps.mutationResult.isError) {
        setErrors(
          useFormProps.mutationResult.error.response.data,
          useFormProps.form,
        )
      }
    },
    // eslint-disable-next-line react-hooks/exhaustive-deps
    [useFormProps.mutationResult.isError],
  )

  return useFormProps
}
export const setErrors = (
  errorData: { [key: string]: string[] },
  form?: FormInstance,
) => {
  Object.entries(errorData).forEach(([field, errors]) => {
    form?.setFields([{ name: field, errors: errors ?? [] }])
  })
}
1reaction
omeraplakcommented, Jul 22, 2022

Hey, We’ve released @pankod/refine-core@3.46.0 👊

Read more comments on GitHub >

github_iconTop Results From Across the Web

Guide to Uncertainty Propagation and Error Analysis
The final step is to propagate error for each step. To do so, we'll need some special formulas that tell us how this...
Read more >
What does "propagate" mean in Swift? - Apple Developer
It just means to transmit, or pass on. But let's not get stuck on the meaning of the word. The quote talks about...
Read more >
Error Handling in Swift - AndyBargh.com
Let's start by looking at how to propagate errors. Propagating Errors. Error Propagation with throws. In Swift, whether or not a function can ......
Read more >
How to Report Errors in Forms: 10 Design Guidelines
These guidelines need little explanation: first, if users don't know that there is a problem with their input, they won't be able to...
Read more >
Notes on the use of propagation of error formulas
The subject of the propagation of errors, on the contrary, is a purely mathematical matter, with very definite and easily ascertained conclusions.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found