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

feat(conform-react): make error array only #229

Merged
merged 1 commit into from
Jul 18, 2023
Merged

Conversation

edmundhung
Copy link
Owner

@edmundhung edmundhung commented Jul 18, 2023

Fix #212.

This is a follow-up of #228 and it expect error always be an array. The impact is mainly internal, except if you are using the base parse helper with custom resolve option, e.g:

function parseFormData(formData: FormData) {
  return parse<SignupForm>(formData, {
    resolve({ email, password, confirmPassword }) {
      const error: Record<string, string[]> = {};

      if (!email) {
        error.email = ['Email is required'];
      } else if (!email.includes('@')) {
        error.email = ['Email is invalid'];
      }

      if (!password) {
        error.password = ['Password is required'];
      }

      if (!confirmPassword) {
        error.confirmPassword = ['Confirm password is required'];
      } else if (confirmPassword !== password) {
        error.confirmPassword = ['Password does not match'];
      }

      if (error.email || error.password || error.confirmPassword) {
        return { error };
      }

      // Return the value only if no error
      return {
        value: {
          email,
          password,
          confirmPassword,
        },
      };
    },
  });
}

@edmundhung edmundhung merged commit 2ace2ef into next Jul 18, 2023
@edmundhung edmundhung deleted the array-only-error branch July 18, 2023 19:57
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

Successfully merging this pull request may close these issues.

1 participant