F
Filament14mo ago
rubendn

Many Identical Forms on the Same Custom Page

Is there a way to add X number of identical forms on the same page on a Custom Page that can be submitted individually? Like an array of forms? I've kind of gotten it to work using Livewire but it would be great if I could use the Filament Fields. The use case is I'm going to have a bunch of images with a form to the right of the image with around 4-5 fields that need to be filled out and submitted. Once one is submitted it hides and the user can continue with the next one. Or is there a way to use a Filament field in a Filament Livewire Custom page but that isn't a part of "Filament" form?
12 Replies
rubendn
rubendnOP14mo ago
Yes, I've seen this but I'm talking about a large number (50+) that are identical and the number is not known ahead of time.
rubendn
rubendnOP14mo ago
I've uploaded a video of what I'm trying to accomplish. This was done in a Filament panel but without using Filament forms.
ZedoX
ZedoX14mo ago
Are you perhaps looking for Repeater/Builder fields?
rubendn
rubendnOP14mo ago
Possibly but I haven't found any kind of similar example to save a new record from a repeater field.
ZedoX
ZedoX14mo ago
You can use ->relationship() on repeaters Or you can just handle it on create, loop through all repeater items, and create a record for each?
rubendn
rubendnOP14mo ago
I've looked all around but can't find any hints on how to do this with a repeater field. The data is not in JSON and I want to be able to save each record individually, not submit and save all the repeaters at the same time. How this is currently working is it reads a folder of images and then creates an array and then a form is created for each image. On save, the data is saved to a new record in the database, the image is moved to a new directory. There is also the option of copying some fields to the next forms On Save if they are going to be the same. The main reason for wanting to do it in a standard Filament form is to be able to use some of the great field types such as a searchable Select and an Input with autocomplete without having to code those. I'm already using the filament blade components for styling purposes.
cheesegrits
cheesegrits14mo ago
You could probably do it with a non-relationship repeater on a table-less form, and use anonymous actions to add a "Save" action to each repeat group, which performs your save logic. I think you would have to uniquely name each action, like appending an iteration count, like Action::make('save-' . $index). And you'd need some visible() logic on each repeat to remove it once saved. And I'm not sure how performant 50+ repeats would be. But should be do-able, at least. https://filamentphp.com/docs/3.x/forms/actions#adding-anonymous-actions-to-a-form-without-attaching-them-to-a-component
cheesegrits
cheesegrits14mo ago
Here's an example of an anonymous action in a repeat, just adding most of the doc example to the demo app ...
No description
rubendn
rubendnOP14mo ago
Thanks @Hugh Messenger I'll try it out. Do you have the code for the quick demo you put together?
cheesegrits
cheesegrits14mo ago
That's just the standard Filament demo, it's in github. I just added an action to show you visually how it looks.
rubendn
rubendnOP14mo ago
Thank you.
Want results from more Discord servers?
Add your server