From e5947ae145993b779b27bd473749dbe0ffdd739d Mon Sep 17 00:00:00 2001 From: Avram Walden Date: Sun, 9 Jun 2024 11:20:34 -0700 Subject: [PATCH] fix: uses unsetCompact for Form filter prop --- src/Form/index.tsx | 4 ++-- tests/components/data.ts | 6 +++--- tests/formComponent.test.tsx | 4 +++- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Form/index.tsx b/src/Form/index.tsx index 3c3d126..7bb4e81 100644 --- a/src/Form/index.tsx +++ b/src/Form/index.tsx @@ -4,7 +4,7 @@ import { type VisitOptions } from '@inertiajs/core' import useInertiaForm, { NestedObject } from '../useInertiaForm' import { useForm, type UseFormProps, type HTTPVerb, FormProvider } from './FormProvider' import FormMetaWrapper, { useFormMeta, type FormMetaValue } from './FormMetaWrapper' -import { unset } from 'lodash' +import { unsetCompact } from '../utils' type PartialHTMLForm = Omit, 'onChange'|'onSubmit'|'onError'> @@ -48,7 +48,7 @@ const Form = ({ const clone = structuredClone(data) filter.forEach(path => { - unset(clone, path) + unsetCompact(clone, path) }) return clone }, [data, filter]) diff --git a/tests/components/data.ts b/tests/components/data.ts index 90999f6..582cb16 100644 --- a/tests/components/data.ts +++ b/tests/components/data.ts @@ -12,9 +12,9 @@ export const multiRootData = { }, contact: { phones: [ - { number: '1234567890' }, - { number: '2234567890' }, - { number: '3234567890' }, + { number: '1234567890', type: 'home' }, + { number: '2234567890', type: 'home' }, + { number: '3234567890', type: 'home' }, ], }, } diff --git a/tests/formComponent.test.tsx b/tests/formComponent.test.tsx index 59f520a..ae2571b 100644 --- a/tests/formComponent.test.tsx +++ b/tests/formComponent.test.tsx @@ -211,6 +211,8 @@ describe('Form Component', () => { expect(form.data.person.last_name).toBeUndefined() expect(form.data.user.username).toBeUndefined() expect(form.data.person.first_name).toBeDefined() + expect(form.data.contact.phones[0].number).toBeDefined() + expect(form.data.contact.phones[0].type).toBeUndefined() } render( @@ -218,7 +220,7 @@ describe('Form Component', () => { model="person" to="/form" data={ multiRootData } - filter={ ['person.last_name', 'user.username'] } + filter={ ['person.last_name', 'user.username', 'contact.phones[].type'] } onChange={ handleChange } >