F
Filament16mo ago
core

AttachAction :use the same modal form for the Edit action in a relationsmanager

My IngredientsRelationManager is working attaching records to the pivot table recipe_ingredient, but the edit action returns a different form in the Modal, (no select "units" dropdown and on edit then the ingredient name is returned as the ingredient_id, in the IngredientsRelationManager table for some reason. what do I need to config? full file gist: https://gist.github.com/dflow/3f3b24109bf08ffad3ab27770e0bc8f0
->headerActions([
// ...
AttachAction::make()
->modalHeading('Add Ingredient')
->modalDescription('Add ingredients, quantities and units')
->modalSubmitActionLabel('Add')
->attachAnother(false)
->preloadRecordSelect()
->label('Add Ingredient')
->form(fn (AttachAction $action): array => [
$action->getRecordSelect(),
Forms\Components\TextInput::make('quantity')->required(),
Select::make('unit')
->label('Unit')
->options(Unit::query()->pluck('unit', 'symbol'))
->required(),
]),

])
->actions([
// ...
Tables\Actions\EditAction::make(),
Tables\Actions\DetachAction::make()
->modalHeading('Remove Ingredient')
->modalIcon('heroicon-o-trash')
->label('Remove'),

])
->headerActions([
// ...
AttachAction::make()
->modalHeading('Add Ingredient')
->modalDescription('Add ingredients, quantities and units')
->modalSubmitActionLabel('Add')
->attachAnother(false)
->preloadRecordSelect()
->label('Add Ingredient')
->form(fn (AttachAction $action): array => [
$action->getRecordSelect(),
Forms\Components\TextInput::make('quantity')->required(),
Select::make('unit')
->label('Unit')
->options(Unit::query()->pluck('unit', 'symbol'))
->required(),
]),

])
->actions([
// ...
Tables\Actions\EditAction::make(),
Tables\Actions\DetachAction::make()
->modalHeading('Remove Ingredient')
->modalIcon('heroicon-o-trash')
->label('Remove'),

])
Gist
AttachAction: use the same modal form for the Edit action in a rela...
AttachAction: use the same modal form for the Edit action in a relationsmanager - gist:3f3b24109bf08ffad3ab27770e0bc8f0
2 Replies
toeknee
toeknee16mo ago
Did the units get cast? I am going to assume there is a casting missing as selects are arrays
core
coreOP15mo ago
no they are not cast, I get a textInput instead of a select on the edit modal
Want results from more Discord servers?
Add your server