Skip to content

feat(form-core): add array method field.filterValues and form.filterFieldValues #1426

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 3 commits into
base: main
Choose a base branch
from

Conversation

Pascalmh
Copy link
Contributor

@Pascalmh Pascalmh commented Apr 17, 2025

Problem

When setting a field back to an empty array

const form = new FormApi({
  defaultValues: {
    people: [
        { firstName: "Bob" },
        { firstName: "Marry" },
    ],
  },
});

form.setFieldValue('people', [
  { firstName: "Marry" }, // <-- "Bob" should be removed
]);

items[0].firstName would still exist - when there's a validation on the firstName (on the Field-level) form.canSubmit would be false.

Solution

adding field.filterValues and form.filterFieldValues to TSF:

form.filterFieldValues(
  'people',
  ({firstName}) => firstName === "Marry"
)

Copy link

nx-cloud bot commented Apr 17, 2025

View your CI Pipeline Execution ↗ for commit da7be72.

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 2m 16s View ↗
nx run-many --target=build --exclude=examples/** ✅ Succeeded 22s View ↗

☁️ Nx Cloud last updated this comment at 2025-04-22 06:25:27 UTC

Copy link

pkg-pr-new bot commented Apr 17, 2025

More templates

@tanstack/angular-form

npm i https://pkg.pr.new/@tanstack/angular-form@1426

@tanstack/form-core

npm i https://pkg.pr.new/@tanstack/form-core@1426

@tanstack/react-form

npm i https://pkg.pr.new/@tanstack/react-form@1426

@tanstack/lit-form

npm i https://pkg.pr.new/@tanstack/lit-form@1426

@tanstack/svelte-form

npm i https://pkg.pr.new/@tanstack/svelte-form@1426

@tanstack/solid-form

npm i https://pkg.pr.new/@tanstack/solid-form@1426

@tanstack/vue-form

npm i https://pkg.pr.new/@tanstack/vue-form@1426

commit: da7be72

Copy link

codecov bot commented Apr 17, 2025

Codecov Report

Attention: Patch coverage is 87.06897% with 15 lines in your changes missing coverage. Please review.

Project coverage is 88.23%. Comparing base (3b90f86) to head (da7be72).

Files with missing lines Patch % Lines
packages/form-core/src/metaHelper.ts 82.71% 13 Missing and 1 partial ⚠️
packages/form-core/src/FormApi.ts 96.77% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1426      +/-   ##
==========================================
- Coverage   88.83%   88.23%   -0.60%     
==========================================
  Files          31       31              
  Lines        1379     1437      +58     
  Branches      347      367      +20     
==========================================
+ Hits         1225     1268      +43     
- Misses        137      151      +14     
- Partials       17       18       +1     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Pascalmh Pascalmh force-pushed the array-filterValues branch from 8a4bb38 to 506523e Compare April 17, 2025 06:47
@Pascalmh Pascalmh changed the title feat(form-core): add array methods clearValues feat(form-core): add array method field.filterValues and form.filterFieldValues Apr 17, 2025
@LeCarbonator
Copy link
Contributor

I think if/when this gets merged, it would be great to rework the Arrays section of the docs to write about swap, insert, push, filter and clear. Thoughts? Should it be somewhere else?

LeCarbonator and others added 2 commits April 20, 2025 17:15
The previous implementation of metaHelper could
lead to passing wrong index combinations with modes.
Splitting them into separate functions allows for explicit
requirements depending on mode.
The previous implementation is preserved for compatability, but
is marked as deprecated.
@LeCarbonator
Copy link
Contributor

LeCarbonator commented Apr 22, 2025

Oof, it did not like that refactor of metaHelper. I'll get to it later today.

Looks like it's beccause I'm trying to avoid a breaking change. I guess I can add some tests for that

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.

2 participants