Repeater

I ma trying do do sth custom with repeater I noticed that a callback is called so many times, and increments at every add items This is a field inside a repeater. I put a dump just to debug it
Components\Toggle::make('is_global')
->visible(fn() => dump()),
Components\Toggle::make('is_global')
->visible(fn() => dump()),
This is a count of printed dump to sequence add items: - First add: 1 dump - Second add: 12 dump - Third add: 23 dump - and so on Why is called so many times?
No description
10 Replies
abdullafahem
abdullafahem6d ago
https://filamentphp.com/docs/3.x/forms/fields/repeater Check here how to use it correctly or please provide more of your code so I can see and try to help you.
galli.roberto
galli.robertoOP6d ago
Is a normal field inside a schema, later I post a code
josef
josef6d ago
I don't get what the problem is? Are you just asking? Or are you trying to accomplish anything specific?
galli.roberto
galli.robertoOP6d ago
The full code
TableRepeater::make('rolesss')
->relationship('roles')
->headers([
Header::make('is_global'),
])
->schema(function (Get $get) {
return [
Components\Toggle::make('is_global')
->visible(fn() => dump(111)),
];
})
TableRepeater::make('rolesss')
->relationship('roles')
->headers([
Header::make('is_global'),
])
->schema(function (Get $get) {
return [
Components\Toggle::make('is_global')
->visible(fn() => dump(111)),
];
})
The attached image show when I load create page and when I add the first Element. My question is why it do a lot of cycle? It is a problem!
No description
No description
galli.roberto
galli.robertoOP6d ago
Too many call for each item, every item add, the item evaluation increase exponentially this is for 3 item add. Sth wrong happen or is it a normal behaviour? If it is the normal behaviour, why? What is the purpose? It happens for visible, I didn't have tried with ohers property
josef
josef6d ago
What's TableRepeater?
awcodes
awcodes6d ago
Does the same thing happen in a normal repeater?
galli.roberto
galli.robertoOP6d ago
yes, i have tried also in filament-demo just now. It happen on visible, i didn't have tried on others property Later I try on other property and make a mini-report It happen only on: - visible - hidden
awcodes
awcodes6d ago
hmm. well, it's a callback inside of a loop, so i would say it's working as expected since each field could be conditionally shown or hidden based on the state of other fields, etc. If you think it is a bug, please submit an issue on GitHub.
galli.roberto
galli.robertoOP5d ago
I used in a wrong way. I used two fields conditionally based on other field to save is_global value, because disabled don't save a value. I mean, I need a toggle button readonly, but ->disabled() make hydratate false, so I fix setting ->diasbled()->dehydratate(true)
Components\Toggle::make('is_global')
->default(UserType::from($get('type'))->isPlaceOwner())
->disabled(UserType::from($get('type'))->isPlaceOwner())
->dehydrated(true) // <----------
Components\Toggle::make('is_global')
->default(UserType::from($get('type'))->isPlaceOwner())
->disabled(UserType::from($get('type'))->isPlaceOwner())
->dehydrated(true) // <----------
Want results from more Discord servers?
Add your server