F
Filament2mo ago
Rilind

How to display default values from relationships in Filament form for dynamic tables?

I have a form in Filament where I’m dynamically generating input fields for different tables using a relationship. Each table has fields like title_label, title_label2, target_label, and value. The value field should be populated with default data from the relationship (reportTable). Here’s a simplified version of my code: return $parameter->tables->map(function ($table) use ($record) { $reportTable = $record?->tables?->where('table_id', $table->id)->first(); return Forms\Components\Section::make() ->schema([ TextInput::make('tables.' . $table->id . '.value') ->label('Real') ->default(fn () => $reportTable?->value) ->placeholder(fn () => $reportTable?->value) ->suffix(setting('unit_of_measurement')), ]); }); The problem I’m facing is that the default values in TextInput::make('tables.' . $table->id . '.value') are not showing up as expected. It seems that the issue lies with the relationship (reportTable) and how I’m using tables.' . $table->id . '.value in the form. The form generates the fields dynamically, but the default values for the value field (which comes from the reportTable relationship) are not displayed correctly. Additionally, when I register the data in the mutation, I need to store the correct value for each table row. How can I correctly display the default values from the relationship in each table’s value field and ensure they are saved correctly? Any help or suggestions would be greatly appreciated!
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server