-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Labels
bugSomething isn't workingSomething isn't working
Description
I have a control defined using withControl and the expected props for the control and the component are reversed.
Screenshots
Code
import { For } from 'solid-js'
import {
createFormGroup,
createFormControl,
withControl,
createFormArray,
bindOwner,
} from 'solid-forms'
import { ItemWithNote } from '../../../server/users/types'
import { H2, Button } from '../../components'
import { TextInput } from '../../components/Forms'
const newItem = (item?: ItemWithNote) =>
createFormGroup({
item: createFormControl(item?.item ?? ''),
note: createFormControl(item?.note ?? ''),
})
const controlFactory = (props: { initialValue: ItemWithNote[] }) => {
return createFormArray<ReturnType<typeof newItem>[]>(
props.initialValue.map(newItem),
)
}
export const ItemWithNoteSet = withControl<
{ title: string },
typeof controlFactory
>({
controlFactory,
component: (props) => {
const array = () => props.control
const onAdd = bindOwner(() => array().push(newItem()))
const onDelete = (index: number) => {
array().removeControl(index)
}
return (
<div>
<H2 class="mb-2">{props.title}</H2>
<Button onclick={onAdd}>Add</Button>
<For each={array().controls}>
{(control, index) => (
<div class="p-4 border rounded mt-2 space-y-2">
<div class="flex justify-between items-start">
<TextInput label="Item" control={control.controls.item} />
<Button danger onclick={() => onDelete(index())}>
Delete
</Button>
</div>
<TextInput label="Note" control={control.controls.note} />
</div>
)}
</For>
</div>
)
},
})Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working

