give each genrePicker cell a unique form id
This commit is contained in:
parent
cd90c92c6d
commit
71f5a44c8e
BIN
prisma/dev.db
BIN
prisma/dev.db
Binary file not shown.
|
@ -24,25 +24,25 @@ export default function GenrePickerInputCell(props: CellContext<any, any>) {
|
||||||
const genres = props.table.options.meta.genres
|
const genres = props.table.options.meta.genres
|
||||||
const [isActive, setIsActive] = useState(false)
|
const [isActive, setIsActive] = useState(false)
|
||||||
|
|
||||||
async function onSubmit({ genres }: { genres: number[] }, event: Event) {
|
async function onSubmit({ genres }: { genres: number[] }) {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
const genresArray = genres.map((e) => { return { id: e } })
|
const genresArray = genres.map((e) => { return { id: e } })
|
||||||
console.log(`genres: ${genres}, genresArray: ${JSON.stringify(genresArray)}`)
|
console.log(`genres: ${genres}, genresArray: ${JSON.stringify(genresArray)}`)
|
||||||
// toast({
|
toast({
|
||||||
// title: "You submitted the following values:",
|
title: "You submitted the following values:",
|
||||||
// description: (
|
description: (
|
||||||
// <pre className="mt-2 w-[340px] rounded-md bg-slate-950 p-4">
|
<pre className="mt-2 w-[340px] rounded-md bg-slate-950 p-4">
|
||||||
// <code className="text-white">{JSON.stringify(genres)}</code>
|
<code className="text-white">{JSON.stringify(genres)}</code>
|
||||||
// </pre>
|
</pre>
|
||||||
// ),
|
),
|
||||||
// })
|
})
|
||||||
// const res = await updateGenres({
|
const res = await updateGenres({
|
||||||
// id,
|
id,
|
||||||
// table,
|
table,
|
||||||
// genres: genresArray,
|
genres: genresArray,
|
||||||
// pathname
|
pathname
|
||||||
// })
|
})
|
||||||
// setIsActive(false)
|
setIsActive(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
function onErrors(errors) {
|
function onErrors(errors) {
|
||||||
|
@ -65,11 +65,14 @@ export default function GenrePickerInputCell(props: CellContext<any, any>) {
|
||||||
genres: value.map(e => e.id)
|
genres: value.map(e => e.id)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const formId = "editGenresForm" + props.cell.id
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
||||||
<Form {...form}>
|
<Form {...form}>
|
||||||
<form onSubmit={form.handleSubmit(onSubmit, onErrors)} id="editGenresForm">
|
<form onSubmit={form.handleSubmit(onSubmit, onErrors)} id={formId}>
|
||||||
<Popover modal={true}>
|
<Popover modal={true} open={isActive} onOpenChange={() => setIsActive(prev => !prev)}>
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="genres"
|
name="genres"
|
||||||
|
@ -119,7 +122,7 @@ export default function GenrePickerInputCell(props: CellContext<any, any>) {
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
<Button variant="ghost" form="editGenresForm">Submit</Button>
|
<Button variant="ghost" form={formId}>Submit</Button>
|
||||||
<Button variant="link" className="p-0" onClick={() => form.setValue("genres", [])}>Clear</Button>
|
<Button variant="link" className="p-0" onClick={() => form.setValue("genres", [])}>Clear</Button>
|
||||||
</PopoverContent>
|
</PopoverContent>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
|
|
Loading…
Reference in New Issue