Get the index of current repeater item
for my case i want to get the index of my repeater item
as i have two repeaters
platforms
products
when i add a platform
i want to set the product for the platform at the same index in products repeater
i dont want to iterate over the platforms repeater array and get the index!
i also want to remove the product if the platform is removed but afterStateUpdated hook is not called on delete of repeater items
i am using AW TableRepeater
@awcodes
Solution:Jump to solution
Table repeater just uses filaments repeater under the hood. But I’m afraid you are going to have to iterate since the array keys for repeaters are UUIDs. Unless you extend the TableRepeater and provide your own hydration and dehydration.
5 Replies
Solution
Table repeater just uses filaments repeater under the hood. But I’m afraid you are going to have to iterate since the array keys for repeaters are UUIDs. Unless you extend the TableRepeater and provide your own hydration and dehydration.
Just note that they may or may not have implications on the actions since the actions use the keys in their callbacks.
also since my product is auto selected based on platform
i want to keep this field disabled
but if i do then it does not save and include this in form request because of
public function
disabled(bool | Closure $condition = true): static
{
$this->isDisabled = $condition;
$this->dehydrated(fn (Component $component): bool => ! $component->evaluate($condition));
return $this;
}``So, tell them to ->dehydrate(true)
Or maybe set them to ->readOnly() instead of disabled()
Iirc, disabled form field, even in the html spec are not included in the form data.
TableRepeater::make('products') >label('Products') ->headers([ Header::make('Product'), Header::make('Quantity'), Header::make('Total Price'), ]) ->schema( function (){ return [ Select::make('product_id') ->readOnly() ->searchable() ->required()tried not working readOnly does not exist on either setting dehydrated after disabled also not working seems to be working fine by adding ->afterStateHydrated(fn (Set $set,$state) => $set('product_id', $state)) ->disabled() ->dehydrated(true) on select column