Coder Social home page Coder Social logo

Comments (7)

AlemTuzlak avatar AlemTuzlak commented on May 18, 2024 1

@fenos Hello! The issue you're facing is the fact that when you return the remix errors from the backend they are consumed internally by the hook until they are cleared in the useActionData (eg you submit again). This means that there is no way to remove the errors via form.clearErrors, but this should not indeed be the case but should be cleared. I will make a patch for this when I get the time and this behavior should remove it so this is definitely not the way it should work. Until then I could recommend that you check if the error that comes from the hook is the same as the be one and clear it like that by using useActionData and handling the errors that way

from remix-hook-form.

Centerworx avatar Centerworx commented on May 18, 2024

Any progress on this? I have just come across the same issue. If you have a recommend solution I can implement it for you.

from remix-hook-form.

AlemTuzlak avatar AlemTuzlak commented on May 18, 2024

Any progress on this? I have just come across the same issue. If you have a recommend solution I can implement it for you.

@Centerworx i think the solution is to have a simple setState that is set to true on submit and false on reset and depending on that it consumes the be errors

from remix-hook-form.

Centerworx avatar Centerworx commented on May 18, 2024

@AlemTuzlak Working on it. There is an issue around useActionData return the value before submit true is set. Even though it is set to true before calling submit handler. But this may just be test implementation issue.

from remix-hook-form.

Centerworx avatar Centerworx commented on May 18, 2024

@AlemTuzlak I have the fix done and tested. I'm having an issue pushing it. Problem with my git.

from remix-hook-form.

xesrevinu avatar xesrevinu commented on May 18, 2024

Hi, first of all, thanks to @AlemTuzlak for making remix-hook-form. I used usePrevious in the project to get the difference of serverErrors and then merged it, which temporarily solved the problem.

  const errors = data?.errors || emptyErrors
  const [serverErrors, setServerErrors] = React.useState(() => errors)
  const previousServerErrors = usePrevious(serverErrors)

  const formErrors = React.useMemo(() => {
    const keys = Object.keys(serverErrors)
    const prevKeys = previousServerErrors ? Object.keys(previousServerErrors) : []
    const deletedErrorKeys = prevKeys.filter((key) => !keys.includes(key))

    const localErrors = methods.formState.errors as FieldErrors<Output>
    const mergedErrors = mergeErrors<Output>(localErrors, serverErrors, validKeys)

    for (const key of deletedErrorKeys) {
      delete mergedErrors[key]
    }

    return mergedErrors
  }, [methods.formState.errors, previousServerErrors, serverErrors, validKeys])

  React.useEffect(() => {
    if (isSubmitting) {
      setServerErrors(emptyErrors)
    } else {
      // Only update the server errors if the form is not submitting
      setServerErrors(errors)
    }
  }, [errors, isSubmitting])

from remix-hook-form.

piotrkulpinski avatar piotrkulpinski commented on May 18, 2024

Is there any progress on this? I just run into the same issue.

from remix-hook-form.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.