Skip to content
This repository was archived by the owner on Oct 14, 2026. It is now read-only.
This repository was archived by the owner on Oct 14, 2026. It is now read-only.

error message doesn't seems to work in usefieldarray #90

Open

Description

@Bat-m

the error dont appear in error message
not sure if this is an issue but cant figure out an other way

const { fields } = useFieldArray({
    name: nameForm,
    ...methods.control
  });

fields.map((field: FieldValues, index: number) => {
            const id = '${nameForm}.${index}.checkbox'

            return (
                <input
                  {...methods.register(id, { required: required })}
                />
              </div>
            );
          })

<ErrorMessage
        errors={errors}
        name={nameForm}
        render={({ message }) => {
          return <div className="text-red-500 text-sm">{message}</div>
        }}
      />

Capture d’écran 2022-02-09 à 10 29 43

Activity

  1. dd8888 commented on Jan 31, 2023

    @dd8888

    I got it working by doing this:

     <ErrorMessage
            errors={methods.formState.errors}
            name={`${name}.root`} <-- This is important
            render={({ message, messages }) => {
              return (
                <span >
                  {message}
                </span>
              );
            }}
          />
    
  2. simonpeters commented on Apr 21, 2023

    @simonpeters

    has anyone got this fixed? above solution doesn't work for me.

  3. iamjaydev commented on Apr 29, 2023

    @iamjaydev

    For my case, yup resolver was causing the issue. (I was using Custom Hook with Resolver Shown in this docs )

    To address the problem,
    I switched to using the @hookform/resolvers package.

    However, I also discovered that using square brackets instead of a dotted name can resolve the issue.

    For example, instead of test.${index}.lasttname, you can use test[${index}].lastName when defining the name property for a Controller component.
    This may be a simpler solution for some cases.

    This works because the square brackets align with the name that Yup uses.

    Hope it helps someone

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions