Skip to content

Commit

Permalink
fix: uses unsetCompact for Form filter prop
Browse files Browse the repository at this point in the history
  • Loading branch information
aviemet committed Jun 9, 2024
1 parent d1deec1 commit e5947ae
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/Form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<React.FormHTMLAttributes<HTMLFormElement>, 'onChange'|'onSubmit'|'onError'>

Expand Down Expand Up @@ -48,7 +48,7 @@ const Form = <TForm extends NestedObject>({

const clone = structuredClone(data)
filter.forEach(path => {
unset(clone, path)
unsetCompact(clone, path)
})
return clone
}, [data, filter])
Expand Down
6 changes: 3 additions & 3 deletions tests/components/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
],
},
}
Expand Down
4 changes: 3 additions & 1 deletion tests/formComponent.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,16 @@ 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(
<Form
model="person"
to="/form"
data={ multiRootData }
filter={ ['person.last_name', 'user.username'] }
filter={ ['person.last_name', 'user.username', 'contact.phones[].type'] }
onChange={ handleChange }
>
<Input name="first_name" />
Expand Down

0 comments on commit e5947ae

Please sign in to comment.