filamentphp / filament

A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS.
https://filamentphp.com
MIT License
18.98k stars 2.93k forks source link

$set in Action within repeater always targets first element #7454

Closed falko100 closed 11 months ago

falko100 commented 1 year ago

Package

filament/filament

Package Version

v3

Laravel Version

v10

Livewire Version

No response

PHP Version

8.2

Problem description

Forms\Components\Repeater::make('Test repeater')
    ->schema([
        Forms\Components\TextInput::make('name')
            ->required()
            ->maxLength(255),

        Forms\Components\Actions::make([
            Forms\Components\Actions\Action::make('change-name')
                ->label('Change name')
                ->action(fn(Forms\Set $set) => $set('name', 'New name'))
        ])
    ]),

https://github.com/filamentphp/filament/assets/11974977/dc835296-2de6-43a7-a416-779934f87c03

Expected behavior

$set should target the entry within the repeater.

Steps to reproduce

Add an action to a repeater's schema and use the $set injection.

Reproduction repository

https://github.com/falko100/filament-bug/tree/bug-reproduction/repeater-set

Relevant log output

No response

falko100 commented 1 year ago

Probably the same issue: $state returns the first element as well.

zepfietje commented 1 year ago

I'm not sure, but IIRC this has been fixed recently. Can you confirm, @falko100?

falko100 commented 1 year ago

Sadly, not fixed yet. I reproduced in a new installation with Filament v3.0.62 Using this code:

Forms\Components\Repeater::make('Test repeater')
    ->schema([
        Forms\Components\TextInput::make('name')
            ->required()
            ->maxLength(255),

        Forms\Components\Actions::make([
            Forms\Components\Actions\Action::make('change-name')
                ->label('Change name')
                ->action(fn(Forms\Set $set) => $set('name', 'New name'))
        ])
    ]),
zepfietje commented 1 year ago

Alright, thanks for checking.

anselmpaul commented 11 months ago

I'm still experiencing this behaviour in 3.0.97, for both $get and $set, any chance this will be addressed soon?

terryw3316 commented 11 months ago

I'm getting a similar issue (3.0.92), though it's not specific to $set, instead I'm attempting to allow for a modal form to display different data depending on the current record of the repeater, but it's always returning the first record.

acobrerosf commented 11 months ago

I'm having the issue here as well. Is there a workaround for this? After some testing it looks like the state path for the actions are always pointing to the first repeater element. The parent action however works ok and the state path points to its right element.

I have a repeater with a file upload input and I need to add a download action button to download the private file but it downloads the first one only.

danharrin commented 11 months ago

Fixed by #7454.