Skip to content

feat(ConnectedForm): Allowing customValidations to be passed to form groups and connected inputs for dynamic validations#3252

Draft
tchryssos wants to merge 11 commits into
mainfrom
tc-add-custom-field-level-validation
Draft

feat(ConnectedForm): Allowing customValidations to be passed to form groups and connected inputs for dynamic validations#3252
tchryssos wants to merge 11 commits into
mainfrom
tc-add-custom-field-level-validation

Conversation

@tchryssos

@tchryssos tchryssos commented Jan 27, 2026

Copy link
Copy Markdown
Contributor

Overview

This PR adds the ability to pass custom validation objects to specific inputs in addition to the validations already included on the top level of the form. This is important because form-level validations are not easy to change dynamically because of both memoization and the need for accessing values "after" the form is instantiated.

There are a few threads kind of about this on the rhf github, but the general conclusions seem to be "you need to be able to access the getValues function when you create your validation rules" and "inlining on the register itself is the place to do wonky stuff".

Since our connected inputs don't actually do the registering themselves and instead hand that responsibility off to the useField hook, I have modified the useField hook to accept customValidations which can be passed to the FormGroup or the input itself. In either case, the custom rules will trickle into useField and successfully MERGE those rules with the ones coming from the form, with customValidations taking priority (since one might want to override a form level rule but the opposite seems unlikely to me).

PR Checklist

  • Related to JIRA ticket: https://skillsoftdev.atlassian.net/browse/WPLAT-3458. This ticket is actually about the VM configurator UX, but this is required to fix that
  • I have run this code to verify it works
  • This PR includes unit tests for the code change
  • This PR includes testing instructions tests for the code change
  • The alpha package of this PR is passing end-to-end tests in all relevant Codecademy repositories

Testing Instructions

Don't make me tap the sign.

  1. See that the tests pass

PR Links and Envs

Repository PR Link
Monolith Monolith PR
Mono Mono PR

@nx-cloud

nx-cloud Bot commented Jan 27, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 59c8992


☁️ Nx Cloud last updated this comment at 2026-06-15 17:45:00 UTC

@codecov

codecov Bot commented Jan 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.90%. Comparing base (01f581f) to head (590c94f).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3252      +/-   ##
==========================================
- Coverage   90.38%   89.90%   -0.49%     
==========================================
  Files         403      270     -133     
  Lines        6638     5664     -974     
  Branches     2149     1908     -241     
==========================================
- Hits         6000     5092     -908     
+ Misses        630      564      -66     
  Partials        8        8              
Flag Coverage Δ
main ?
pull-request 89.90% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dreamwasp dreamwasp left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this makes sense to me - you're seeing some type errors with nested chedkboxes that need to be resolved but if you fix that type + add docs its good to go

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR extends Gamut’s ConnectedForm system to support field-level, dynamically-evaluated validation rules via a new customValidations prop. It’s designed to complement (and override) memoized form-level validationRules, enabling cross-field/runtime-dependent validation logic while keeping the Connected* input abstractions intact.

Changes:

  • Adds customValidations support to useField and threads it through ConnectedFormGroup, Connected inputs, and useDebouncedField, merging with form-level rules (field-level taking priority).
  • Updates Styleguide docs and Storybook examples to document and demonstrate runtime-dependent validation use cases.
  • Adds unit tests covering custom-only validations, override behavior, and merging behavior.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/styleguide/src/lib/Organisms/ConnectedForm/ConnectedFormInputs/ConnectedFormInputs.mdx Documents the new field-level customValidations capability and usage patterns.
packages/styleguide/src/lib/Organisms/ConnectedForm/ConnectedForm/ConnectedForm.stories.tsx Adds a Storybook example demonstrating runtime-dependent validations via customValidations.
packages/styleguide/src/lib/Organisms/ConnectedForm/ConnectedForm/ConnectedForm.mdx Adds a section linking to customValidations usage and renders the new story.
packages/gamut/src/ConnectedForm/utils.tsx Implements merging of form-level validation rules with customValidations in useField and plumbs through useDebouncedField.
packages/gamut/src/ConnectedForm/ConnectedInputs/types.tsx Extends connected input prop types to accept customValidations.
packages/gamut/src/ConnectedForm/ConnectedInputs/ConnectedTextArea.tsx Passes customValidations into useField.
packages/gamut/src/ConnectedForm/ConnectedInputs/ConnectedSelect.tsx Passes customValidations into useField.
packages/gamut/src/ConnectedForm/ConnectedInputs/ConnectedRadioGroupInput.tsx Threads customValidations through the radio group input wrapper (but currently misses passing it to individual radios).
packages/gamut/src/ConnectedForm/ConnectedInputs/ConnectedRadioGroup.tsx Accepts customValidations and uses it for required-state computation/registration flow.
packages/gamut/src/ConnectedForm/ConnectedInputs/ConnectedRadio.tsx Passes customValidations into useField.
packages/gamut/src/ConnectedForm/ConnectedInputs/ConnectedNestedCheckboxes/index.tsx Passes customValidations into useField.
packages/gamut/src/ConnectedForm/ConnectedInputs/ConnectedInput.tsx Passes customValidations into useField.
packages/gamut/src/ConnectedForm/ConnectedInputs/ConnectedCheckbox.tsx Passes customValidations into useField.
packages/gamut/src/ConnectedForm/ConnectedFormGroup.tsx Extracts and forwards customValidations from field prop into useField and the rendered connected input.
packages/gamut/src/ConnectedForm/tests/useField.test.tsx Adds test coverage for custom-only, override, and merged validation behavior.
Comments suppressed due to low confidence (1)

packages/gamut/src/ConnectedForm/ConnectedInputs/ConnectedRadioGroupInput.tsx:22

  • customValidations is not passed down to the ConnectedRadio children. Since each radio registers the field (and ConnectedRadioGroup doesn't attach the register ref to an input), field-level validations may not be enforced for radio groups when provided via customValidations.
          <ConnectedRadio
            disabled={disabled}
            key={`${name}-${elem.value}`}
            name={name}
            {...elem}
          />

@codecademydev

Copy link
Copy Markdown
Collaborator

📬 Published Alpha Packages:

Package Version npm Diff
@codecademy/gamut 71.0.1-alpha.c9e50f.0 npm diff
@codecademy/gamut-icons 9.57.8-alpha.c9e50f.0 npm diff
@codecademy/gamut-illustrations 0.58.14-alpha.c9e50f.0 npm diff
@codecademy/gamut-kit 2.0.1-alpha.c9e50f.0 npm diff
@codecademy/gamut-patterns 0.10.33-alpha.c9e50f.0 npm diff
@codecademy/gamut-styles 20.0.1-alpha.c9e50f.0 npm diff
@codecademy/gamut-tests 6.0.4-alpha.c9e50f.0 npm diff
@codecademy/variance 0.26.2-alpha.c9e50f.0 npm diff
eslint-plugin-gamut 2.4.4-alpha.c9e50f.0 npm diff

@github-actions

Copy link
Copy Markdown
Contributor

@tchryssos tchryssos requested a review from dreamwasp June 15, 2026 17:51
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.

4 participants