Skip to content

feat(form-core): add onDynamicListenTo validator option #1710

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jiji-hoon96
Copy link

Adds onDynamicListenTo validator option to enable automatic dynamic validation when specified fields change, following the same pattern as existing onChangeListenTo and onBlurListenTo options.

Changes

  • Type definitions: Added onDynamicListenTo?: DeepKeys<TParentData>[] to FieldValidators
  • Core logic: Extended getLinkedFields() to support dynamic validation cause
  • Auto-trigger: Modified setValue() to automatically trigger dynamic validation on linked fields
  • Validation logic: Added dynamic case support in defaultValidationLogic
  • Tests: Comprehensive test coverage for sync/async scenarios and multiple field listening
  • Documentation: Added usage guide and examples in React linked fields documentation

Usage

<form.Field
  name="confirmPassword"
  validators={{
    onDynamicListenTo: ['password'],
    onDynamic: ({ value, fieldApi }) => {
      if (value !== fieldApi.form.getFieldValue('password')) {
        return 'Passwords do not match'
      }
    }
  }}
>
  {/* Field render */}
</form.Field>

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