fix: useField validated-only mode for arrays (#5029)
## Summary
- Fix `useField.validate()` to properly handle `validated-only` mode by checking the field's `validated` flag before deciding whether to run full validation with error mutation or silent validation
- Previously, `validated-only` mode was treated identically to `force` mode in `useField`, which caused fields that hadn't been interacted with yet to get incorrectly marked as validated and have error messages set when `useFieldArray` triggered form-wide validation
- Add comprehensive test coverage for `useFieldArray` with object items, covering schema validation, meta updates (valid/dirty), nested property mutations via `computedDeep`, and interaction with `useField`
## Details
When `useFieldArray.update()` calls `form.validate({ mode: 'validated-only' })` (triggered by `computedDeep` when `field.value` properties change), each `useField` instance's `validate()` function is invoked. Previously, any mode other than `silent` would call `validateWithStateMutation()`, which:
1. Sets `meta.validated = true`
2. Runs validation
3. Sets error messages on the field
This was problematic because it would show errors on fields the user hadn't interacted with yet, and incorrectly mark them as validated. The fix adds a check: in `validated-only` mode, if the field hasn't been validated before (`!meta.validated`), use `validateValidStateOnly()` instead, which only updates the `valid` flag without setting errors.
## Test plan
- [x] Verify `useFieldArray` with object items triggers schema validation and updates `meta.valid`
- [x] Verify `meta.dirty` updates correctly when pushing object items
- [x] Verify nested property mutations (`field.value.name = ''`) trigger validation
- [x] Verify `useField` components work correctly with nested field array paths
- [x] Verify explicit `form.validate()` shows errors on pushed object fields
- [x] Verify errors propagate to `extraErrorsBag` when no `useField` is used
- [x] Verify typing in `useField`-bound inputs triggers validation and shows errors
- [x] Verify no regression in existing `FieldArray.spec.ts` tests
- [x] All 367 tests pass (3 pre-existing failures unrelated to this change)
Closes #5029
🤖 Generated with [Claude Code](https://claude.com/claude-code)
合并状态:未合并 3 条评论