Skip to content

fix: clean validation on additional input list remove#208

Open
tomrndom wants to merge 2 commits intomainfrom
fix/mui-additional-input-list-remove
Open

fix: clean validation on additional input list remove#208
tomrndom wants to merge 2 commits intomainfrom
fix/mui-additional-input-list-remove

Conversation

@tomrndom
Copy link
Copy Markdown
Contributor

@tomrndom tomrndom commented Apr 2, 2026

ref: https://app.clickup.com/t/86b8t9k79

Signed-off-by: Tomás Castillo tcastilloboireau@gmail.com

Summary by CodeRabbit

  • Bug Fixes
    • Reset form "touched" state when removing items from dynamic input lists so validation messages are cleared and remain accurate.

Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
@tomrndom tomrndom requested a review from smarcet April 2, 2026 13:55
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 2, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5dac1d8f-b3c1-4371-b0eb-662c3c39d0b0

📥 Commits

Reviewing files that changed from the base of the PR and between df72b73 and a23d703.

📒 Files selected for processing (1)
  • src/components/mui/formik-inputs/additional-input/additional-input-list.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/mui/formik-inputs/additional-input/additional-input-list.js

📝 Walkthrough

Walkthrough

Destructures setFieldTouched from Formik context in AdditionalInputList and calls setFieldTouched(name, [], false) inside handleRemove after updating the field value, resetting the touched state when an item is removed.

Changes

Cohort / File(s) Summary
Formik Context Integration
src/components/mui/formik-inputs/additional-input/additional-input-list.js
Destructured setFieldTouched from useFormikContext and added a call to setFieldTouched(name, [], false) in handleRemove after setFieldValue to clear the touched state for the field path upon item removal.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 I hop and I tidy the form with care,

I clear the "touched" with a whiskered flair,
Removed items vanish, no warnings to see,
Validation sleeps calm as can be. ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: cleaning validation state when removing items from an additional input list component, which aligns with the changeset that adds setFieldTouched reset logic to handleRemove.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/mui-additional-input-list-remove

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/components/mui/formik-inputs/additional-input/additional-input-list.js`:
- Line 70: The call to setFieldTouched should be moved inside removeFromUI and
only invoked after a successful removal to avoid clearing touched state on API
failure; update the invocation from setFieldTouched(name, []) to
setFieldTouched(name, false) and call it after the code path that confirms the
item was removed (i.e., inside removeFromUI or immediately after a successful
API response), and ensure no unconditional setFieldTouched call remains where
the API call could still fail.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 564e6f1a-94a3-4297-aeff-66ae486ef95e

📥 Commits

Reviewing files that changed from the base of the PR and between 54bca4e and df72b73.

📒 Files selected for processing (1)
  • src/components/mui/formik-inputs/additional-input/additional-input-list.js

}
setFieldValue(name, newValues);
};
setFieldTouched(name, [], false);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🌐 Web query:

Formik setFieldTouched API signature and parameters - what is the second parameter type?

💡 Result:

The Formik setFieldTouched API signature is: setFieldTouched: (field: string, isTouched?: boolean, shouldValidate?: boolean) => Promise<void> The second parameter is isTouched, which is a boolean (optional, defaults to true). It sets whether the specified field is touched.

Citations:


🏁 Script executed:

cat -n src/components/mui/formik-inputs/additional-input/additional-input-list.js | sed -n '25,80p'

Repository: OpenStackweb/openstack-uicore-foundation

Length of output: 2024


Move setFieldTouched call inside removeFromUI to prevent inconsistent state on API failure.

The setFieldTouched call at line 70 executes unconditionally after confirmation, before the conditional removal logic. If the API call (line 73) fails and is caught at line 75, the touched state is already cleared but the item remains in the list, leaving form state inconsistent.

Additionally, passing [] as the second parameter to setFieldTouched violates Formik's API—the parameter must be a boolean (isTouched?: boolean). The correct value is false to clear the touched state.

🐛 Proposed fix: move setFieldTouched inside removeFromUI
     const removeFromUI = () => {
       const newValues = metaFields.filter((_, idx) => idx !== index);
       if (newValues.length === 0) {
         newValues.push({ ...DEFAULT_META_FIELD, _key: `draft_${Date.now()}` });
       }
       setFieldValue(name, newValues);
+      setFieldTouched(name, false, false);
     };
-    setFieldTouched(name, [], false);

     if (item.id && onDelete) {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
setFieldTouched(name, [], false);
const removeFromUI = () => {
const newValues = metaFields.filter((_, idx) => idx !== index);
if (newValues.length === 0) {
newValues.push({ ...DEFAULT_META_FIELD, _key: `draft_${Date.now()}` });
}
setFieldValue(name, newValues);
setFieldTouched(name, false, false);
};
if (item.id && onDelete) {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/mui/formik-inputs/additional-input/additional-input-list.js`
at line 70, The call to setFieldTouched should be moved inside removeFromUI and
only invoked after a successful removal to avoid clearing touched state on API
failure; update the invocation from setFieldTouched(name, []) to
setFieldTouched(name, false) and call it after the code path that confirms the
item was removed (i.e., inside removeFromUI or immediately after a successful
API response), and ensure no unconditional setFieldTouched call remains where
the API call could still fail.

Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
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