© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
8 replies
nowak

Setting defaulItems count dynamically in repeater field

I have a repeater field for product SKU's, that I want to predefine the items for depending on the product type and attribute.

I have attached my ProductResource form that clarifies what I am trying to achieve.

So in the defaultItems() method I am attempting to set the number based on the input of the
product_type_id
product_type_id
field and the
attribute_id
attribute_id
field. But it seems like it only returns the output of the initial function run, and not upon later changes to the input fields.

In the documentation it says this:
Note that these default items are only created when the form is loaded without existing data. Inside panel resources this only works on Create Pages, as Edit Pages will always fill the data from the model.
https://filamentphp.com/docs/3.x/forms/fields/repeater#setting-empty-default-items

Which makes me think that live setting of defaultItems() is not possible, since it might only be triggered when the form is loaded?

I might be mistaken, but this is the only explanation I have for the behaviour I see.

Is there another way to set the item count of a repeater field dynamically, like I set addable() and deletable()?

Or if using another approach than repeater fields would be more appropriate for my use case, then please let me know!

Thank you!
message.txt5.27KB
Repeater - Form Builder - Filament
Solution
On both of the live() fields you call afterStateUpdated() and in the callback you $get the value of the other field, do your check to make sure they both have values then $set() the repeater field.

So, your afterStateUpdated callback is going to need $get, $set and $state.

So setting the repeater would just be something like
$set(‘repeatername’, [
    [‘name’ => null],
    [‘name’ => null],
    …repeat for the number of items you need
])
$set(‘repeatername’, [
    [‘name’ => null],
    [‘name’ => null],
    …repeat for the number of items you need
])
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Dynamically change defaultItems in Repeater
FilamentFFilament / ❓┊help
3y ago
Dynamically change Form component in Repeater
FilamentFFilament / ❓┊help
2y ago
Setting helperText dynamically.
FilamentFFilament / ❓┊help
3y ago
Setting Values in a repeater
FilamentFFilament / ❓┊help
3y ago