fix: radio buttons with same name handle errors correctly (#5001)
## Summary
- **Fixes #5001**: When multiple `<Field>` components share the same `name` (e.g. radio buttons), only the last one would receive validation errors
- The root cause was that `createPathState` only reused existing path states for fields explicitly typed as `checkbox` or `radio`. When `type` was not specified on the `<Field>` component (common when wrapping radio inputs in a custom component), separate path states were created, and only the last one in the lookup would receive errors from `setFieldError`
- The fix makes `createPathState` reuse existing path states for ALL fields sharing the same path, not just checkbox/radio types. It also updates `removePathState` and unmount logic to properly handle shared non-multiple fields
## Changes
- `packages/vee-validate/src/useForm.ts`: Broadened the `createPathState` reuse condition to match any field with the same path (with a normalized path identity check to avoid stale field array paths). Updated `removePathState` to decrement `fieldsCount` for all shared fields and only remove the path state when `fieldsCount <= 0`
- `packages/vee-validate/src/useField.ts`: Updated the unmount ID matching logic to handle array IDs regardless of `multiple` flag. Only unsets path values when it is the last field or a radio/checkbox group
- `packages/vee-validate/tests/Form.spec.ts`: Added two regression tests for #5001 and updated the #4643 test to reflect the new shared pathState behavior
## Test plan
- [x] New test: radio buttons without `type="radio"` on Field should all show errors when they share the same name
- [x] New test: radio buttons with `type="radio"` and same name should all show errors via v-slot
- [x] Updated existing test for #4643 to match new shared pathState structure
- [x] All 357 existing tests pass (3 pre-existing failures in unrelated suites: i18n, toTypedSchema, validate.spec)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
合并状态:未合并 3 条评论