AttachAction in relationManager

I have a question about a situation I'm encoutring on my project. I have a PartnersRelationManager into my projectResource, I'm using create action if there are no partners to attach and then I show the attach btn. But what I really want, is to add a create btn in the attachAction, so I can create a new partner if I didn't find the exact partner to attach from the select list. Any ideas?? Thank you
Solution:
```php ->headerActions([ Tables\Actions\AttachAction::make() ->preloadRecordSelect() // Preload the select field values ->recordSelect(fn (Select $select) => $select->placeholder(__('projProgRelations.choosePartner'))) // change the select placeholder text...
Jump to solution
13 Replies
Mokatchi
MokatchiOP5d ago
I used this code an I got the following screenshots
->headerActions([
Tables\Actions\AttachAction::make()
->label(__('Attach Partner')) // Set your custom label
->preloadRecordSelect() // Preload the select field values
->recordSelect(fn (Select $select) =>
$select->placeholder(__('projProgRelations.choosePartner')),)
->form(fn (AttachAction $action): array => [
$action->getRecordSelect()

->createOptionForm([
TextInput::make('organism')
->label(__('projProgRelations.organism'))
->maxLength(255)
->required(),
TextInput::make('name')
->label(__('projProgRelations.agentName')),
TextInput::make('gsm')
->label(__('projProgRelations.agentGsm'))
->tel()
->unique(ignoreRecord:true)
->maxLength(10),
TextInput::make('phone')
->label(__('projProgRelations.organismPhone'))
->tel()
->unique(ignoreRecord:true)
->maxLength(10),
TextInput::make('email')
->label(__('projProgRelations.agentEmail'))
->email()
->maxLength(255)
->unique(ignoreRecord:true),
]),
]),
])
->headerActions([
Tables\Actions\AttachAction::make()
->label(__('Attach Partner')) // Set your custom label
->preloadRecordSelect() // Preload the select field values
->recordSelect(fn (Select $select) =>
$select->placeholder(__('projProgRelations.choosePartner')),)
->form(fn (AttachAction $action): array => [
$action->getRecordSelect()

->createOptionForm([
TextInput::make('organism')
->label(__('projProgRelations.organism'))
->maxLength(255)
->required(),
TextInput::make('name')
->label(__('projProgRelations.agentName')),
TextInput::make('gsm')
->label(__('projProgRelations.agentGsm'))
->tel()
->unique(ignoreRecord:true)
->maxLength(10),
TextInput::make('phone')
->label(__('projProgRelations.organismPhone'))
->tel()
->unique(ignoreRecord:true)
->maxLength(10),
TextInput::make('email')
->label(__('projProgRelations.agentEmail'))
->email()
->maxLength(255)
->unique(ignoreRecord:true),
]),
]),
])
Mokatchi
MokatchiOP5d ago
No description
No description
toeknee
toeknee5d ago
->extraModalFooterActions() and place your creation action in here. Then you can create if you can't find one in search.
Mokatchi
MokatchiOP4d ago
And without using the whole code under the recordSelect(...) ? Hello, can you please give me more details because I couldn't make it work.
toeknee
toeknee4d ago
->extraModalFooterActions([
Action::make('create')->form(['The Form')]->action(fn($data) => MyModel::create($record)->id);
])
->extraModalFooterActions([
Action::make('create')->form(['The Form')]->action(fn($data) => MyModel::create($record)->id);
])
very rough quickfreehand code
Mokatchi
MokatchiOP4d ago
I used Filament\Tables\Actions\Action (which is working) because the Filament\Forms\Components\Actions\Action produces an error of instantiation must to be done first then I can proceed. The problem here is when I click on "soumettre" btn nothing happend, no error and no database record insertion done. It's like it's not submitted, Any ideas?
No description
No description
toeknee
toeknee4d ago
try: ->formForm([]) on the action
Mokatchi
MokatchiOP4d ago
here is my code
Tables\Actions\AttachAction::make()
->label(__('Attach Partner')) // Set your custom label
->preloadRecordSelect() // Preload the select field values
->recordSelect(fn (Select $select) => $select->placeholder(__('projProgRelations.choosePartner')),) // change the select placeholder text
->extraModalFooterActions([
Action::make('create')
->form([
TextInput::make('organism')
->label(__('projProgRelations.organism'))
->maxLength(255)
->required(),
TextInput::make('name')
->label(__('projProgRelations.agentName')),
TextInput::make('gsm')
->label(__('projProgRelations.agentGsm'))
->tel()
->unique(ignoreRecord:true)
->maxLength(10),
TextInput::make('phone')
->label(__('projProgRelations.organismPhone'))
->tel()
->unique(ignoreRecord:true)
->maxLength(10),
TextInput::make('email')
->label(__('projProgRelations.agentEmail'))
->email()
->maxLength(255)
->unique(ignoreRecord:true),
]) ])
->action(fn (array $data) => Partner::create($data))
Tables\Actions\AttachAction::make()
->label(__('Attach Partner')) // Set your custom label
->preloadRecordSelect() // Preload the select field values
->recordSelect(fn (Select $select) => $select->placeholder(__('projProgRelations.choosePartner')),) // change the select placeholder text
->extraModalFooterActions([
Action::make('create')
->form([
TextInput::make('organism')
->label(__('projProgRelations.organism'))
->maxLength(255)
->required(),
TextInput::make('name')
->label(__('projProgRelations.agentName')),
TextInput::make('gsm')
->label(__('projProgRelations.agentGsm'))
->tel()
->unique(ignoreRecord:true)
->maxLength(10),
TextInput::make('phone')
->label(__('projProgRelations.organismPhone'))
->tel()
->unique(ignoreRecord:true)
->maxLength(10),
TextInput::make('email')
->label(__('projProgRelations.agentEmail'))
->email()
->maxLength(255)
->unique(ignoreRecord:true),
]) ])
->action(fn (array $data) => Partner::create($data))
I didn't get any result on the docs about this method
toeknee
toeknee4d ago
Place it:
Action::make('create')
->fillForm([])
->form([
Action::make('create')
->fillForm([])
->form([
just to test if nothing happens, then on the Partner dd() it to see if ti's being hit.
Mokatchi
MokatchiOP4d ago
I tried to dd the data in the action function but nothing showed up, and I also tried to log some text there, but nothing logged. do you mean to place form( .... ) by fillForm(....)?
toeknee
toeknee4d ago
try changing create to create_partner No i did not
Mokatchi
MokatchiOP3d ago
@toeknee ​ Here is the final solution : You can acheive it without the ->form(....) but if you want to control the creation form, it's good to use it.
Solution
Mokatchi
Mokatchi3d ago
->headerActions([
Tables\Actions\AttachAction::make()
->preloadRecordSelect() // Preload the select field values
->recordSelect(fn (Select $select) => $select->placeholder(__('projProgRelations.choosePartner'))) // change the select placeholder text
->extraModalFooterActions([
Tables\Actions\CreateAction::make()
->form([
TextInput::make('organism')
->label(__('projProgRelations.organism'))
->maxLength(255)
->required(),
TextInput::make('name')
->label(__('projProgRelations.agentName')),
TextInput::make('gsm')
->label(__('projProgRelations.agentGsm'))
->tel()
->unique(ignoreRecord:true)
->maxLength(10),
TextInput::make('phone')
->label(__('projProgRelations.organismPhone'))
->tel()
->unique(ignoreRecord:true)
->maxLength(10),
TextInput::make('email')
->label(__('projProgRelations.agentEmail'))
->email()
->maxLength(255)
->unique(ignoreRecord:true),
])
])
])
->headerActions([
Tables\Actions\AttachAction::make()
->preloadRecordSelect() // Preload the select field values
->recordSelect(fn (Select $select) => $select->placeholder(__('projProgRelations.choosePartner'))) // change the select placeholder text
->extraModalFooterActions([
Tables\Actions\CreateAction::make()
->form([
TextInput::make('organism')
->label(__('projProgRelations.organism'))
->maxLength(255)
->required(),
TextInput::make('name')
->label(__('projProgRelations.agentName')),
TextInput::make('gsm')
->label(__('projProgRelations.agentGsm'))
->tel()
->unique(ignoreRecord:true)
->maxLength(10),
TextInput::make('phone')
->label(__('projProgRelations.organismPhone'))
->tel()
->unique(ignoreRecord:true)
->maxLength(10),
TextInput::make('email')
->label(__('projProgRelations.agentEmail'))
->email()
->maxLength(255)
->unique(ignoreRecord:true),
])
])
])
Want results from more Discord servers?
Add your server