Skip to content

Add isOneOf validation.#83

Open
cdeutsch wants to merge 1 commit intomasterfrom
is-one-of
Open

Add isOneOf validation.#83
cdeutsch wants to merge 1 commit intomasterfrom
is-one-of

Conversation

@cdeutsch
Copy link
Copy Markdown
Owner

@cdeutsch cdeutsch commented Mar 20, 2026


EntelligenceAI PR Summary

Adds an isOneOf validation feature that restricts a form field's value to a predefined set of allowed options.

  • src/interfaces.ts: Extended ErrorType union with 'isOneOf' and added isOneOf?: Value[] to FormFieldConfig
  • src/validations.ts: Added isOneOf validator that passes for empty fields or values matching any entry in the allowed list
  • demo/pages/index.tsx: Integrated tShirtSize field using isOneOf: ['small', 'medium', 'large'] with corresponding error message and FormInput rendering

Confidence Score: 1/5 - Blocking Issues

  • Two confirmed runtime bugs: tshirtSize vs tShirtSize case mismatch will cause the field value to always be undefined, breaking form submission silently
  • The isOneOf validation in validations.ts is never called from FormsProvider.tsx, meaning an entire validation rule is completely non-functional — a logic bug that will cause silent validation failures
  • Both bugs are functional correctness issues (not style/nit), have been flagged across multiple review cycles as unresolved, and would ship broken behavior to users
  • Neither issue appears to have been addressed despite repeated comments in prior reviews, indicating the PR is not ready for merge
Files requiring special attention
  • demo/pages/index.tsx
  • src/validations.ts

Summary by CodeRabbit

  • New Features
    • Added t-shirt size field to the user form with options: small, medium, or large
    • Introduced validation support to restrict form fields to predefined value options
    • Enhanced error messages to guide users when invalid selections are submitted

Copy link
Copy Markdown

@entelligence-ai-pr-reviews entelligence-ai-pr-reviews bot left a comment

Choose a reason for hiding this comment

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

Walkthrough

This PR introduces an isOneOf validation rule across the codebase, enabling form fields to restrict input to a predefined set of acceptable values. The new validation type is added to the ErrorType union and FormFieldConfig interface, implemented in the validations logic, and demonstrated with a new tShirtSize field in the demo page.

Changes

File(s) Summary
src/interfaces.ts Added isOneOf to the ErrorType union and an optional isOneOf?: Value[] property to FormFieldConfig.
src/validations.ts Added isOneOf validation rule that returns true if the field is empty or if the value exists within the allowed values array.
demo/pages/index.tsx Added tShirtSize to UserFormFields, introduced an isOneOf validation config entry with error text, and rendered the field as a FormInput component.

🔗 Cross-Repository Impact Analysis

Enable automatic detection of breaking changes across your dependent repositories. → Set up now

Learn more about Cross-Repository Analysis

What It Does

  • Automatically identifies repositories that depend on this code
  • Analyzes potential breaking changes across your entire codebase
  • Provides risk assessment before merging to prevent cross-repo issues

How to Enable

  1. Visit Settings → Code Management
  2. Configure repository dependencies
  3. Future PRs will automatically include cross-repo impact analysis!

Benefits

  • 🛡️ Prevent breaking changes across repositories
  • 🔍 Catch integration issues before they reach production
  • 📊 Better visibility into your multi-repo architecture

Comment on lines 72 to +78
<FormInput key={email.name} formField={email} />

<FormInput
key={tshirtSize.name}
formField={tshirtSize}
autoComplete="off"
placeholder="small, medium, or large"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Correctness: The destructured field is tshirtSize but the UserFormFields interface and formFieldConfigs define it as tShirtSize (camelCase with capital S). This will be undefined at runtime, causing a crash when accessing tshirtSize.name.

Affected Locations:

  • demo/pages/index.tsx:72-78
  • demo/pages/index.tsx:11-11
  • demo/pages/index.tsx:48-48
🤖 AI Agent Prompt for Cursor/Windsurf

📋 Copy this prompt to your AI coding assistant (Cursor, Windsurf, etc.) to get help fixing this issue

In demo/pages/index.tsx, lines 72-78, the variable `tshirtSize` is used but the UserFormFields interface and formFieldConfigs define it as `tShirtSize` (capital S). Fix the destructuring in the render method from `tshirtSize` to `tShirtSize` and update all usages of `tshirtSize` in this block to `tShirtSize` to match the interface definition and avoid a runtime crash.

Comment on lines +98 to +100
isOneOf(formField: FormField, formFields: FormFields, submitting: boolean, allowedValues: Value[]) {
return !isExisty(formField.value) || isEmpty(formField.value) || allowedValues.includes(formField.value);
},
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Correctness: The new isOneOf validation is never invoked in FormsProvider.tsx's isValid function, so even if a formFieldConfig.isOneOf is configured, it will silently be ignored and no validation error will be pushed.

🤖 AI Agent Prompt for Cursor/Windsurf

📋 Copy this prompt to your AI coding assistant (Cursor, Windsurf, etc.) to get help fixing this issue

In src/FormsProvider.tsx, inside the `isValid` function, add a call to `validations.isOneOf` similar to the other validations. After the `minLength` block (around line 434), add:

```typescript
if (formFieldConfig.isOneOf && !validations.isOneOf(formField, formFields, submitting, formFieldConfig.isOneOf)) {
  errors.push('isOneOf');
}

Also ensure FormFieldConfig interface includes an isOneOf?: Value[] property.


</details>
<!-- ai_prompt_end -->

Copy link
Copy Markdown

@entelligence-ai-pr-reviews entelligence-ai-pr-reviews bot left a comment

Choose a reason for hiding this comment

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

Walkthrough

This PR introduces an isOneOf validation type across the codebase, enabling form fields to restrict input to a predefined set of allowed values. Changes span the validation logic, type interfaces, and a demo form that adds a tShirtSize field using this new validation. A minor naming inconsistency exists in the demo between the destructured variable (tshirtSize) and the interface field (tShirtSize).

Changes

File(s) Summary
src/interfaces.ts Adds isOneOf to the ErrorType union and adds an optional isOneOf property (accepting Value[]) to FormFieldConfig.
src/validations.ts Adds an isOneOf validation function that returns true if the field is empty or its value exists in the provided allowedValues array.
demo/pages/index.tsx Adds tShirtSize field to UserFormFields interface and form config with isOneOf validation restricted to 'small', 'medium', 'large'; renders a corresponding FormInput with autocomplete-off and placeholder text; includes a minor naming bug (tshirtSize vs tShirtSize).

Sequence Diagram

This diagram shows the interactions between components:

sequenceDiagram
    participant User as User
    participant Home as Home Component
    participant CF as ClassyForm
    participant FCC as FormsContextContext
    participant FI as FormInput
    participant GE as getErrorText

    Note over Home: formFieldConfigs now includes tShirtSize field
    Home->>CF: render with formFieldConfigs
    Note over CF: configs: firstName, lastName,<br/>email, tShirtSize (isOneOf: small/medium/large)

    CF->>FCC: provide formFields context
    FCC-->>Home: { firstName, lastName, email, tShirtSize, onSubmit }

    Home->>FI: render <FormInput formField={firstName} />
    Home->>FI: render <FormInput formField={lastName} />
    Home->>FI: render <FormInput formField={email} />
    Home->>FI: render <FormInput formField={tShirtSize} autoComplete="off" placeholder="small, medium, or large" />

    User->>FI: enters value in tShirtSize field

    alt valid value (small, medium, or large)
        FI->>GE: getHelperText(tShirtSize, formFields)
        GE-->>FI: no error
    else invalid value
        FI->>GE: getHelperText(tShirtSize, formFields)
        Note over GE: case 'isOneOf'
        GE-->>FI: "Must be small, medium, or large"
        FI-->>User: display helper text error
    end

    User->>FI: submit form
    FI->>FCC: onSubmit(formData)
Loading

🔗 Cross-Repository Impact Analysis

Enable automatic detection of breaking changes across your dependent repositories. → Set up now

Learn more about Cross-Repository Analysis

What It Does

  • Automatically identifies repositories that depend on this code
  • Analyzes potential breaking changes across your entire codebase
  • Provides risk assessment before merging to prevent cross-repo issues

How to Enable

  1. Visit Settings → Code Management
  2. Configure repository dependencies
  3. Future PRs will automatically include cross-repo impact analysis!

Benefits

  • 🛡️ Prevent breaking changes across repositories
  • 🔍 Catch integration issues before they reach production
  • 📊 Better visibility into your multi-repo architecture

Comment on lines 71 to +77

<FormInput key={email.name} formField={email} />

<FormInput
key={tshirtSize.name}
formField={tshirtSize}
autoComplete="off"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Correctness: The destructured field is tshirtSize (camelCase, no capital S) but the UserFormFields interface defines it as tShirtSize (capital S), and the formFieldConfigs array also uses tShirtSize. This means tshirtSize will be undefined at runtime, causing a crash when accessing tshirtSize.name.

🤖 AI Agent Prompt for Cursor/Windsurf

📋 Copy this prompt to your AI coding assistant (Cursor, Windsurf, etc.) to get help fixing this issue

In demo/pages/index.tsx, lines 71-77, the variable `tshirtSize` is used but the interface `UserFormFields` defines the field as `tShirtSize` (capital S). The destructuring on the render method also uses `tshirtSize` (lowercase s) which won't match the actual field key. Fix the destructuring from `tshirtSize` to `tShirtSize` and update all references in these lines to `tShirtSize`.

Comment on lines 71 to +77

<FormInput key={email.name} formField={email} />

<FormInput
key={tshirtSize.name}
formField={tshirtSize}
autoComplete="off"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Correctness: The destructured field is tshirtSize (camelCase, no capital S) but the UserFormFields interface defines it as tShirtSize (capital S), and the formFieldConfigs array also uses tShirtSize. This means tshirtSize will be undefined at runtime, causing a crash when accessing tshirtSize.name.

Affected Locations:

  • demo/pages/index.tsx:71-77
  • demo/pages/index.tsx:11-14
  • demo/pages/index.tsx:46-46
🤖 AI Agent Prompt for Cursor/Windsurf

📋 Copy this prompt to your AI coding assistant (Cursor, Windsurf, etc.) to get help fixing this issue

In demo/pages/index.tsx, lines 71-77, the variable `tshirtSize` is used but the interface `UserFormFields` defines the field as `tShirtSize` (capital S). The destructuring on the render method also uses `tshirtSize` (lowercase s) which won't match the actual field key. Fix the destructuring from `tshirtSize` to `tShirtSize` and update all references in these lines to `tShirtSize`.

Comment on lines +98 to +100
isOneOf(formField: FormField, formFields: FormFields, submitting: boolean, allowedValues: Value[]) {
return !isExisty(formField.value) || isEmpty(formField.value) || allowedValues.includes(formField.value);
},
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Correctness: The new isOneOf validation is never invoked in FormsProvider.tsx's isValid function, unlike every other validation rule — meaning formFieldConfig.isOneOf will never be evaluated and validation will silently pass.

🤖 AI Agent Prompt for Cursor/Windsurf

📋 Copy this prompt to your AI coding assistant (Cursor, Windsurf, etc.) to get help fixing this issue

In `src/FormsProvider.tsx`, inside the `isValid` function, add a call to `validations.isOneOf` after the `minLength` block (around line 434), following the same pattern as the other validations:

```ts
if (formFieldConfig.isOneOf && !validations.isOneOf(formField, formFields, submitting, formFieldConfig.isOneOf)) {
  errors.push('isOneOf');
}

Also ensure FormFieldConfig includes an isOneOf property typed as Value[] | undefined.


</details>
<!-- ai_prompt_end -->

Copy link
Copy Markdown

@entelligence-ai-pr-reviews entelligence-ai-pr-reviews bot left a comment

Choose a reason for hiding this comment

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

Walkthrough

This PR introduces an isOneOf validation type across the form validation system. It adds the new error type and config property to the interfaces, implements the validation logic to check if a field's value belongs to a predefined set of allowed values, and demonstrates the feature in the demo app with a t-shirt size field restricted to 'small', 'medium', or 'large'.

Changes

File(s) Summary
src/interfaces.ts Added isOneOf to the ErrorType union and an optional isOneOf?: Value[] property to FormFieldConfig.
src/validations.ts Implemented isOneOf validation method that returns true if the field is empty or its value is in the allowed list.
demo/pages/index.tsx Added tShirtSize field to UserFormFields, a new isOneOf validation case with error text, a FormFieldConfig entry, and rendered a corresponding FormInput in the demo form.

Sequence Diagram

This diagram shows the interactions between components:

sequenceDiagram
    participant User as User
    participant Home as Home Component
    participant CF as ClassyForm
    participant FI as FormInput
    participant GE as getErrorText

    Note over Home: formFieldConfigs includes<br/>firstName, lastName, email,<br/>+ tShirtSize (isOneOf validation)

    Home->>CF: render with formFieldConfigs
    activate CF
    CF-->>Home: FormsContextContext<br/>{ formFields: { firstName, lastName,<br/>email, tshirtSize }, onSubmit }

    Home->>FI: render FormInput(firstName)
    Home->>FI: render FormInput(lastName)
    Home->>FI: render FormInput(email)
    Home->>FI: render FormInput(tshirtSize)<br/>placeholder="small, medium, or large"<br/>autoComplete="off"

    User->>FI: enters value in tShirtSize field
    activate FI
    FI->>GE: getHelperText(tShirtSize, formFields)
    activate GE

    alt value not provided
        GE-->>FI: 'Required'
    else value not in [small, medium, large]
        GE-->>FI: 'Must be small, medium, or large'
    else valid value
        GE-->>FI: (no error)
    end
    deactivate GE
    deactivate FI

    User->>CF: submit form (onSubmit)
    CF-->>User: registration with tShirtSize submitted
    deactivate CF
Loading

🔗 Cross-Repository Impact Analysis

Enable automatic detection of breaking changes across your dependent repositories. → Set up now

Learn more about Cross-Repository Analysis

What It Does

  • Automatically identifies repositories that depend on this code
  • Analyzes potential breaking changes across your entire codebase
  • Provides risk assessment before merging to prevent cross-repo issues

How to Enable

  1. Visit Settings → Code Management
  2. Configure repository dependencies
  3. Future PRs will automatically include cross-repo impact analysis!

Benefits

  • 🛡️ Prevent breaking changes across repositories
  • 🔍 Catch integration issues before they reach production
  • 📊 Better visibility into your multi-repo architecture

Comment on lines 72 to +78
<FormInput key={email.name} formField={email} />

<FormInput
key={tshirtSize.name}
formField={tshirtSize}
autoComplete="off"
placeholder="small, medium, or large"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Correctness: The destructured field is tshirtSize but the UserFormFields interface and formFieldConfigs use tShirtSize (camelCase with capital S) — this will resolve to undefined at runtime, causing a crash when accessing tshirtSize.name.

🤖 AI Agent Prompt for Cursor/Windsurf

📋 Copy this prompt to your AI coding assistant (Cursor, Windsurf, etc.) to get help fixing this issue

In demo/pages/index.tsx, lines 72-78, the FormInput for t-shirt size uses `tshirtSize` but the UserFormFields interface declares `tShirtSize` (capital S). Fix the destructuring in the ClassyForm render prop from `tshirtSize` to `tShirtSize` and update the key and formField props accordingly to avoid a runtime crash.

Comment on lines 72 to +78
<FormInput key={email.name} formField={email} />

<FormInput
key={tshirtSize.name}
formField={tshirtSize}
autoComplete="off"
placeholder="small, medium, or large"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Correctness: The destructured field is tshirtSize but the UserFormFields interface and formFieldConfigs use tShirtSize (camelCase with capital S) — this will resolve to undefined at runtime, causing a crash when accessing tshirtSize.name.

Affected Locations:

  • demo/pages/index.tsx:72-78
  • demo/pages/index.tsx:46-46
🤖 AI Agent Prompt for Cursor/Windsurf

📋 Copy this prompt to your AI coding assistant (Cursor, Windsurf, etc.) to get help fixing this issue

In demo/pages/index.tsx, lines 72-78, the FormInput for t-shirt size uses `tshirtSize` but the UserFormFields interface declares `tShirtSize` (capital S). Fix the destructuring in the ClassyForm render prop from `tshirtSize` to `tShirtSize` and update the key and formField props accordingly to avoid a runtime crash.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 20, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 29e04063-dd68-483f-bc55-a3b6739c7949

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • ✅ Review completed - (🔄 Check again to review again)
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

CodeRabbit can use TruffleHog to scan for secrets in your code with verification capabilities.

Add a TruffleHog config file (e.g. trufflehog-config.yml, trufflehog.yml) to your project to customize detectors and scanning behavior. The tool runs only when a config file is present.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

♻️ Duplicate comments (2)
demo/pages/index.tsx (1)

62-79: ⚠️ Potential issue | 🔴 Critical

Case mismatch: tshirtSize vs tShirtSize will cause runtime crash.

The destructured variable tshirtSize (lowercase 's') doesn't match the interface definition tShirtSize (capital 'S') on line 14 or the config name on line 49. This will be undefined at runtime, causing a TypeError when accessing tshirtSize.name.

🐛 Proposed fix
-          {({
-            formFields: { email, firstName, lastName, tshirtSize },
-            onSubmit,
-          }: FormsContextContext<UserFormFields>) => {
+          {({
+            formFields: { email, firstName, lastName, tShirtSize },
+            onSubmit,
+          }: FormsContextContext<UserFormFields>) => {
                 <FormInput
-                  key={tshirtSize.name}
-                  formField={tshirtSize}
+                  key={tShirtSize.name}
+                  formField={tShirtSize}
                   autoComplete="off"
                   placeholder="small, medium, or large"
                 />
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@demo/pages/index.tsx` around lines 62 - 79, The destructured form field name
uses "tshirtSize" but the interface/config defines "tShirtSize", causing
undefined at runtime; update the destructuring in the FormsContext callback to
use the exact identifier "tShirtSize" (i.e., change formFields: { email,
firstName, lastName, tshirtSize } to use tShirtSize) so FormInput receives a
valid formField, and ensure any other references (keys, placeholder assignment)
use tShirtSize to match the UserFormFields definition and the config name.
src/validations.ts (1)

98-100: ⚠️ Potential issue | 🔴 Critical

Validation function is defined but never invoked.

The isOneOf validation implementation looks correct, but it is not integrated into FormsProvider.tsx's isValid function. This means even when formFieldConfig.isOneOf is configured, the validation will silently be skipped and always pass.

Add the corresponding check in FormsProvider.tsx:

if (formFieldConfig.isOneOf && !validations.isOneOf(formField, formFields, submitting, formFieldConfig.isOneOf)) {
  errors.push('isOneOf');
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/validations.ts` around lines 98 - 100, The isOneOf validator in
validations.ts (isOneOf(formField, formFields, submitting, allowedValues)) is
implemented but never called from FormsProvider.tsx; update the isValid function
in FormsProvider.tsx to check for formFieldConfig.isOneOf and call
validations.isOneOf with the formField, formFields, submitting flag, and
formFieldConfig.isOneOf array, and if it returns false push 'isOneOf' into the
errors array (i.e., add the conditional: if (formFieldConfig.isOneOf &&
!validations.isOneOf(...)) { errors.push('isOneOf'); } so configured isOneOf
rules are enforced).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@demo/pages/index.tsx`:
- Around line 62-79: The destructured form field name uses "tshirtSize" but the
interface/config defines "tShirtSize", causing undefined at runtime; update the
destructuring in the FormsContext callback to use the exact identifier
"tShirtSize" (i.e., change formFields: { email, firstName, lastName, tshirtSize
} to use tShirtSize) so FormInput receives a valid formField, and ensure any
other references (keys, placeholder assignment) use tShirtSize to match the
UserFormFields definition and the config name.

In `@src/validations.ts`:
- Around line 98-100: The isOneOf validator in validations.ts
(isOneOf(formField, formFields, submitting, allowedValues)) is implemented but
never called from FormsProvider.tsx; update the isValid function in
FormsProvider.tsx to check for formFieldConfig.isOneOf and call
validations.isOneOf with the formField, formFields, submitting flag, and
formFieldConfig.isOneOf array, and if it returns false push 'isOneOf' into the
errors array (i.e., add the conditional: if (formFieldConfig.isOneOf &&
!validations.isOneOf(...)) { errors.push('isOneOf'); } so configured isOneOf
rules are enforced).

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c17f2ec3-d0e8-42a7-9656-8007568b1cfd

📥 Commits

Reviewing files that changed from the base of the PR and between 8f578e5 and 67175d9.

📒 Files selected for processing (3)
  • demo/pages/index.tsx
  • src/interfaces.ts
  • src/validations.ts

@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Mar 20, 2026

Greptile Summary

This PR adds an isOneOf validation rule that restricts a form field's value to a predefined set of allowed options. The interface, validator function, and demo integration are all present, but two previously-flagged bugs remain unresolved and prevent the feature from working correctly at runtime.

  • isOneOf validator is never invoked: validations.isOneOf is defined in src/validations.ts, but the isValid() function in src/FormsProvider.tsx (lines 344–443) has no corresponding dispatch block for isOneOf. Every other validator has an explicit if (formFieldConfig.X && !validations.X(...)) check — isOneOf is missing one. As a result, any field configured with isOneOf silently passes validation regardless of its value.
  • tshirtSize / tShirtSize casing mismatch: The field is registered in formFieldConfigs and UserFormFields as tShirtSize (capital S), but it is destructured as tshirtSize (lowercase s) on line 63 of demo/pages/index.tsx. Because the key does not exist in formFields, tshirtSize will be undefined at runtime, and accessing tshirtSize.name on line 75 will throw a TypeError.

Both of these bugs were raised in prior review cycles and have not been addressed in this revision.

Confidence Score: 1/5

  • Not safe to merge — two confirmed runtime bugs remain unresolved after multiple review cycles.
  • The isOneOf validator is entirely non-functional because no dispatch block was added to isValid() in FormsProvider.tsx, meaning the feature ships with zero effect. Additionally, the tshirtSize casing mismatch in demo/pages/index.tsx causes a TypeError at runtime when the demo page renders. Both issues were flagged in prior reviews and are still present in the current diff.
  • demo/pages/index.tsx (casing mismatch causing TypeError) and src/FormsProvider.tsx (missing isOneOf dispatch block — not in the diff but must be updated for the feature to work).

Important Files Changed

Filename Overview
src/interfaces.ts Correctly extends ErrorType union with 'isOneOf' and adds isOneOf?: Value[] to FormFieldConfig. No issues.
src/validations.ts Adds the isOneOf validator function with correct logic, but it is never invoked from isValid() in src/FormsProvider.tsx (no dispatch block added), making the entire validator non-functional at runtime.
demo/pages/index.tsx Contains a case-mismatch bug: the field is registered as tShirtSize but destructured as tshirtSize (lowercase s), causing undefined at runtime and a TypeError when tshirtSize.name is accessed on line 75.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Form Submit / onBlur / onChange] --> B[validateFormFields]
    B --> C[isValid per field]
    C --> D{formFieldConfig.required?}
    D -- Yes --> E[validations.isDefaultRequiredValue]
    E --> F[push 'required' error]
    C --> G{formFieldConfig.isEmail?}
    G -- Yes --> H[validations.isEmail]
    H --> I[push 'isEmail' error]
    C --> J{formFieldConfig.isOneOf?}
    J -- Yes --> K["❌ NO DISPATCH BLOCK EXISTS\n(missing from FormsProvider.tsx)"]
    K --> L[isOneOf error NEVER pushed]
    C --> M[... other validators ...]
    style K fill:#ff4444,color:#fff
    style L fill:#ff4444,color:#fff
Loading

Last reviewed commit: "Add isOneOf valida..."

Comment on lines +98 to +100
isOneOf(formField: FormField, formFields: FormFields, submitting: boolean, allowedValues: Value[]) {
return !isExisty(formField.value) || isEmpty(formField.value) || allowedValues.includes(formField.value);
},
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P0 isOneOf validator is never invoked — validation is completely non-functional

validations.isOneOf is defined here, but the isValid() function in src/FormsProvider.tsx (lines 344–443) contains an explicit if block for every other validation rule and has no corresponding check for isOneOf. Because FormsProvider.tsx is the only place validations are dispatched, any field configured with isOneOf will silently pass validation regardless of its value.

The following block must be added to isValid() in src/FormsProvider.tsx, alongside the other validator checks:

  if (
    formFieldConfig.isOneOf &&
    !validations.isOneOf(formField, formFields, submitting, formFieldConfig.isOneOf)
  ) {
    errors.push('isOneOf');
  }

Without this change, the entire feature introduced by this PR has no effect at runtime.

Comment on lines +63 to +64
formFields: { email, firstName, lastName, tshirtSize },
onSubmit,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P0 tshirtSize casing mismatch causes runtime crash

The field is configured in formFieldConfigs with name: 'tShirtSize' (capital S) and declared in UserFormFields as tShirtSize, but it is destructured here as tshirtSize (lowercase s). Because the key does not exist in formFields, tshirtSize will be undefined at runtime. Accessing tshirtSize.name on line 75 will then throw a TypeError.

Fix the destructured name to match the registered field name:

Suggested change
formFields: { email, firstName, lastName, tshirtSize },
onSubmit,
formFields: { email, firstName, lastName, tShirtSize },

Also update lines 75–79 to reference tShirtSize instead of tshirtSize.

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