ModalContent inputs pass to action()

BulkAction use modalContent custom view blade with inputs - how to pass input values to action after confirm modalDialog?
Solution:
add public $notes = []; to your ListPage inject $livewire in the action: ```php...
Jump to solution
9 Replies
LeandroFerreira
LeandroFerreira2mo ago
why not using ->form()?
BulkAction::make('customAction')
->form([
TextInput::make('field')
])
->action(function (array $data, Collection $records) {
dd($data, $records);
})
BulkAction::make('customAction')
->form([
TextInput::make('field')
])
->action(function (array $data, Collection $records) {
dd($data, $records);
})
Csinesz
CsineszOP2mo ago
Csinesz
CsineszOP2mo ago
I've tried wire:model etc. but dont work
BulkAction::make('group_wise_transfer')
->action(function (BulkAction $action, Collection $records, array $data) {
dump($action->getModalContent()->getData());
dump($data);

Notification::make()
->title("Utalás elindítva: " . count($records) . " db számla")
->duration(5000)
->success()
->send();
})
->label('Csoportos utalás')
->requiresConfirmation()
->modalWidth('5xl') // Set custom modal width

->modalContent(function (Collection $records): View {

// CUSTOM LOGIC GOES HERE


return view('filament.pages.wise-group-modal', ['all_fee' => $allTransferFee, 'all_gross' => $allGross, 'records' => $toFunding, 'existing' => null]);
})
->color('primary')
->icon('heroicon-s-arrow-right'),
BulkAction::make('group_wise_transfer')
->action(function (BulkAction $action, Collection $records, array $data) {
dump($action->getModalContent()->getData());
dump($data);

Notification::make()
->title("Utalás elindítva: " . count($records) . " db számla")
->duration(5000)
->success()
->send();
})
->label('Csoportos utalás')
->requiresConfirmation()
->modalWidth('5xl') // Set custom modal width

->modalContent(function (Collection $records): View {

// CUSTOM LOGIC GOES HERE


return view('filament.pages.wise-group-modal', ['all_fee' => $allTransferFee, 'all_gross' => $allGross, 'records' => $toFunding, 'existing' => null]);
})
->color('primary')
->icon('heroicon-s-arrow-right'),
Solution
LeandroFerreira
LeandroFerreira2mo ago
add public $notes = []; to your ListPage inject $livewire in the action:
->action(function (BulkAction $action, Collection $records, array $data, Pages\YourListPage $livewire) {
dd($livewire->notes);
})
->action(function (BulkAction $action, Collection $records, array $data, Pages\YourListPage $livewire) {
dd($livewire->notes);
})
Csinesz
CsineszOP2mo ago
Can I use it in Resource file?
LeandroFerreira
LeandroFerreira2mo ago
no, because your ListPage is the livewire component. What is the problem to add this to your ListPage?
Csinesz
CsineszOP2mo ago
Thank you it works! Only one thing - the values dont be filled in this step:
<input class="..." wire:model.defer="notes.{{ $key }}" type="text" value="{{ $record['notes'] }}">
<input class="..." wire:model.defer="notes.{{ $key }}" type="text" value="{{ $record['notes'] }}">
livewire and value dont love each other 🙂
LeandroFerreira
LeandroFerreira2mo ago
use mountUsing to fill $notes
BulkAction::make('group_wise_transfer')
->mountUsing(function (Pages\YourListPage $livewire) {
$livewire->notes = ['xxx', 'yyy'];
})
...
BulkAction::make('group_wise_transfer')
->mountUsing(function (Pages\YourListPage $livewire) {
$livewire->notes = ['xxx', 'yyy'];
})
...
Csinesz
CsineszOP2mo ago
Thank you @Leandro Ferreira you saved my day. Everíthing working now.
->mountUsing(function (BulkAction $action, ListAdminInvoices $livewire) {
foreach ($action->getModalContent()->getData()['records'] as $value) {
$livewire->notes[] = $value['notes'];
}
})
->mountUsing(function (BulkAction $action, ListAdminInvoices $livewire) {
foreach ($action->getModalContent()->getData()['records'] as $value) {
$livewire->notes[] = $value['notes'];
}
})

Did you find this page helpful?