awcodes / filament-table-repeater

A modified version of the Filament Forms Repeater to display it as a table.
MIT License
188 stars 42 forks source link

Select relationship value not retained after saving #66

Closed brianakidd closed 10 months ago

brianakidd commented 10 months ago

Filament Version

v3

Plugin Version

v2

PHP Version

8.1

Problem description

Using a Form Select inside the repeater with a createOptionForm, the created option is saved and associated with the repeater relationship but, after save, the select is cleared. Refreshing the page then shows the select value.

TableRepeater::make('clientContacts')
    ->label('Contacts')
    ->relationship()
    ->schema([
        Forms\Components\Select::make('contact_id')
            ->relationship('contact', 'name')
            ->required()
            ->searchable()
            ->createOptionForm([
                Forms\Components\TextInput::make('name')
                    ->required(),
                Forms\Components\TextInput::make('email')
                    ->email(),
                Forms\Components\TextInput::make('office_phone')
                    ->tel(),
                Forms\Components\TextInput::make('mobile_phone')
                    ->tel()
                ])->createOptionModalHeading('Create Contact'),
        Forms\Components\TextInput::make('description')
    ])

https://github.com/awcodes/filament-table-repeater/assets/6431835/5546f16b-01e7-47ce-b5ac-6b67b4aa6f45

Expected behavior

The expected behavior is that the select value would remain after saving.

Steps to reproduce

In a form, add the TableRepeater referencing a relationship and within the TableRepeater schema, include a Select with a createOptionForm. Open an existing record that contains the TableRepeater and attempt to add a new relationship by clicking the suffix create action then save.

Reproduction repository

No response

Relevant log output

No response

awcodes commented 10 months ago

I wonder if this is a bug in the filament repeater or a livewire issue? Can you update to the latest filament and if the issue is still there try to replicate it in a regular repeater?

This plugin uses the filament repeater under the hood it just changes the layout. So there's nothing in the plugin, that I can think of, that would have a direct conflict with saving data.

brianakidd commented 10 months ago

@awcodes Sorry I'm just getting back to you. I changed my form to use the Filament Repeater and the value is retained after save. Seems odd if you are using the Filament Repeater in the background but I can confirm it is behaving differently. Let me know how I can help.

awcodes commented 10 months ago

If you could provide a reproduction repo, that would be a huge help.

brianakidd commented 10 months ago

I've created the repo and found that during create, the TableRepeater Select retains the created relationship but during edit, it does not. Provided high-level steps to reproduce in the readme. Hope this helps.

https://github.com/brianakidd/filament-table-repeater-error.git

awcodes commented 10 months ago

Thank you. I will look at it as soon as I can and get back to you.