Repeater custom input names based on if it is relationship or currently added
Hello,
I have a FormBuilder/Repeater with some fields in it with custom
name
attributes to be able to be submited with the page. I set the input name with ->extraInputAttributes(['name' => 'promotions[promo_from]'])
.
How can I check if current Repeater iteration its comming from existing relation(is existing record) and to change the input name
to use the relation id as key as follows:
Repeater (relation: promotions)
.. then on click of the repeater "add new" button, the keys of the names to be sequential
Currently I have the following schema for a filament form
6 Replies
Is there someting like.. 👀
I'm not sure I fully understand the context of what you are trying to do but, if this can help, I think you can pass a closure to extraInputAttributes:
Oh, it doesn't help... But nice to know that this is also supported
'name' => function($get)
😄The last pease of code is just example code, that i wish I had, its just pseudo code.
But you can look at this line
return 'promotions['.$number.'][promo_from]'
I need $number
to get the record id from the current iteration of the repeater, and based on that apply different name with the ID of the record, or if it is not a record, then do a sequential order based on Repeater's children count.
Did I explain it better this time?Well yeah, I think I understand. Sorry, I'm not sure I can help you as much as I thought on this one! I think you're going a bit off the beaten path 🤠
Try this in your Edit page:
You should see your repeater's data in there, and all items should have a key of
record-{id}
. Maybe this can be useful?I'm not using the admin package, only the form builder.
Someone else have any ideas?
this is not what the form builder was built for, you should be binding fields to Livewire properties
submitting them via normal controllers is not supported