Skip to content

🐞 fix(getValidateError): treat an empty message array from validate as valid - #13937

Merged
bluebill1049 merged 1 commit into
react-hook-form:masterfrom
Enesuygurs:fix/validate-empty-message-array
Oct 22, 2026
Merged

bluebill1049 merged 1 commit into
react-hook-form:masterfrom
Enesuygurs:fix/validate-empty-message-array

Conversation

@Enesuygurs

Copy link
Copy Markdown
Contributor

Proposed Changes

ValidateResult allows a validate function to return Message[], and getValidateError treats an array of strings as a failure. The check was Array.isArray(result) && result.every(isString), and [].every(...) is always true, so an empty array is also reported as an error, with an empty message.

An empty array is what you naturally get when messages are collected with filter/map:

register('password', {
  validate: {
    rules: (value) =>
      [value.length < 8 && 'too short', !/\d/.test(value) && 'needs a digit'].filter(Boolean),
  },
});

With a valid value the rule returns [], yet errors.password is { type: 'rules', message: '' }, isValid stays false, and submit is blocked with no visible message.

This change only treats the array as an error when it is non-empty. Non-empty arrays behave exactly as before.

No existing issue covers this.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works (getValidateError.test.ts and validateField.test.tsx; both fail before the change)
  • New and existing tests pass locally with my changes (jest, pnpm type, pnpm test:type, pnpm lint)

@bluebill1049 bluebill1049 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good fix!

@bluebill1049
bluebill1049 merged commit 33f65e5 into react-hook-form:master Oct 22, 2026
6 checks passed
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.

2 participants