F
Filament15mo ago
ElCoco

RepeatableEntry, state array data and suffix actions. How to get the repeatable state in the action.

I have this infolist, $this->conversation->history returns an array (stored as JSON in the DB) :
public function conversationInfolist(Infolist $infolist): Infolist
{
return $infolist
// ->record($this->conversation)
->state([
'history' => $this->conversation->history
])
->schema([
FilamentInfolists\RepeatableEntry::make('history')
->hiddenLabel(true)
->schema([
FilamentInfolists\TextEntry::make('conversation.input_text')
->hiddenLabel(true),
FilamentInfolists\TextEntry::make('conversation.output_text')
->label(' ')
->suffixActions([
Action::make('thumbsup')
->icon('heroicon-m-hand-thumb-up')
->action(function (Get $get) {
dd($get('something'));
}),
Action::make('thumbsdown')
->icon('heroicon-m-hand-thumb-down')
->action(function (Conversation $record) {
})

])
])
->contained(true)
])
->columns(1);
}
public function conversationInfolist(Infolist $infolist): Infolist
{
return $infolist
// ->record($this->conversation)
->state([
'history' => $this->conversation->history
])
->schema([
FilamentInfolists\RepeatableEntry::make('history')
->hiddenLabel(true)
->schema([
FilamentInfolists\TextEntry::make('conversation.input_text')
->hiddenLabel(true),
FilamentInfolists\TextEntry::make('conversation.output_text')
->label(' ')
->suffixActions([
Action::make('thumbsup')
->icon('heroicon-m-hand-thumb-up')
->action(function (Get $get) {
dd($get('something'));
}),
Action::make('thumbsdown')
->icon('heroicon-m-hand-thumb-down')
->action(function (Conversation $record) {
})

])
])
->contained(true)
])
->columns(1);
}
I need to have the current state of the repeater in the thumbsup/thumbsdown actions. I tried to inject the $state variable and it throws the messsage:
An attempt was made to evaluate a closure for [Filament\Infolists\Components\Actions\Action], but [$state] was unresolvable.
An attempt was made to evaluate a closure for [Filament\Infolists\Components\Actions\Action], but [$state] was unresolvable.
Injecting Get as you see in the example gives:
Typed property Filament\Forms\Components\Component::$container must not be accessed before initialization
Typed property Filament\Forms\Components\Component::$container must not be accessed before initialization
Someone has any idea of what should I do to get some state out of the repeatable. Actually getting just the INDEX of the array in the repeater loop would already make me pretty happy...
3 Replies
Pete Foresttree
Pete Foresttree15mo ago
I'm running into the same issue. I have a feeling this is impossible.
zydnrbrn
zydnrbrn11mo ago
i have same issue, have you found the solution?
Luc Van Keer
Luc Van Keer6mo ago
I think you should use a closure as parameter for suffixAction. You can inject the state there.
Want results from more Discord servers?
Add your server