#Error getEditOptionActionFormData when using editOptionForm in Select without a relationship

12 messages · Page 1 of 1 (latest)

distant willow
#

Hello.
I have a select:

Select::make('decedent_id')

with the createOptionForm() working correctly now, and I also need the user to be able to edit, so I added the code for the edit:

->editOptionForm([
     DatePicker::make('date_of_death')
                  ->displayFormat('d M Y')
                  ->required()
                  ->minDate(now()->subYears(120))
                  ->maxDate(now()->subDays(1))
                  ->label(__('date_of_death'))
                  ->placeholder(__('date_of_death'))
                  ->columnSpan(4),
  ])

But when I select one existing data from the dropdown it thows the error:
Filament\Forms\Components\Select::getEditOptionActionFormData(): Return value must be of type array, null returned

Any ideas of how to solve this? I suppose it is not a problem to enable both the createOption and the editOption at the same time. Is it that way?

Thanks.

rotund burrowBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

agile owl
#

I am guessing youm need:

editOptionActionFormData([
$data here?
])

this is a new feature I am not familiar with

distant willow
#

Yes. I suppose it is something like that, but I have been trying blindly with no success.
Any example could help, please.

agile owl
#

editOptionActionFormData(fn($record) => $record)

?

distant willow
#

Nope. Already tried but no results.

agile owl
#

editOptionActionFormData(fn($record) => $record->toArray())

#

Can you provide your code I think I know hy

distant willow
#

Someone helped me with the createOption
https://discord.com/channels/883083792112300104/1148349791013703720

But with the same idea, edit is not working. If you go to definition on function getEditOptionActionFormData it expects an array and gets it from fillEditOptionActionFormUsing. I tried:

->fillEditOptionActionFormUsing(function ($record, $data) {
      $person = Person::find($data['decedent_id']);
      $person->fill($data);
      $person->save();
      return $person->id;
  })

And error now is ==> An attempt was made to evaluate a closure for [Filament\Forms\Components\Select], but [$data] was unresolvable.

agile owl
#

The whole code, that's just a fill edit code.

distant willow
#

The whole select field code is too long. A file is created but you can see:


smoky iris
#

same problem. Have you resolve this bug ?

An attempt was made to evaluate a closure for [App\Forms\Components\Select], but [$data] was unresolvable.