Custom Modal View for ViewAction

Is it possible to load a custom view into the ViewAction Modal so I can render the data differently? Background: Because the default ViewAction just takes the Form and disables all Inputs but it doesn’t work well for Multiselects / Tag Inputs so I would like to change that for a better UI. Thank you! 🙏
36 Replies
awcodes
awcodes2y ago
No, but you can make your own action to either show a view in a modal or redirect to a custom page to view the record.
Prodex
ProdexOP2y ago
Thanks! Can I use the modal component from filament so I don’t need to create my own modal and logic for it?
Dennis Koch
Dennis Koch2y ago
You can just use Action::make()->modalContent()
awcodes
awcodes2y ago
Yes, the Action class support modals out of the box.
Prodex
ProdexOP2y ago
Oh nice, thank you! 🙏 Hi Dennis, just tried this, but the modal doesn't show up right now:
->actions([
Tables\Actions\Action::make('view')
->label('')
->icon('heroicon-o-eye')
->modalHeading('Test')
->modalContent(view('filament.modals.view-incident')),
])
->actions([
Tables\Actions\Action::make('view')
->label('')
->icon('heroicon-o-eye')
->modalHeading('Test')
->modalContent(view('filament.modals.view-incident')),
])
I think as the docs say, every action needs a ->action(), but I don't understand how this needs to be setup if you just want a modal with extra information of that record and a close button. From my understanding there isn't a real "action" behind it.
toeknee
toeknee2y ago
You need an ->action()
Prodex
ProdexOP2y ago
yes, but ->action() needs a callback and as I said above this should only display information of the record
toeknee
toeknee2y ago
That's fine, but you still need an action for it to render fn() => '' so
->actions([
Tables\Actions\Action::make('view')
->label('')
->icon('heroicon-o-eye')
->modalHeading('Test')
->action(fn() => '')
->modalContent(view('filament.modals.view-incident')),
])
->actions([
Tables\Actions\Action::make('view')
->label('')
->icon('heroicon-o-eye')
->modalHeading('Test')
->action(fn() => '')
->modalContent(view('filament.modals.view-incident')),
])
Prodex
ProdexOP2y ago
ah okay, and how can I access the $record inside the modal view?
toeknee
toeknee2y ago
if you have a custom view i.e. view-incident then you can just get it within there with the closures $get i.e.
$evaluate(fn ($get) => $get('my_field'))
$evaluate(fn ($get) => $get('my_field'))
Prodex
ProdexOP2y ago
okay, sorry for my noob questions but you mean inline php inside blade? so {{ $evaluate(fn ($get) => $get('my_field')) }}
toeknee
toeknee2y ago
in here view('filament.modals.view-incident') you are calling a custom blade view so {{ $evaluate(fn ($get) => $get('my_field')) }} inside filament\modals\view-incident.blade.php
Prodex
ProdexOP2y ago
okay, I get Undefined variable $evaluate and I think it would be better if I could pass $record to the view so I can do things like $record->title etc. Can I somehow achieve this?
Dan Harrin
Dan Harrin2y ago
->modalContent(fn ($record) => view('filament.modals.view-incident', ['record' => $record])) evaluation only works in things like form fields and table columns
toeknee
toeknee2y ago
An action has a form? So assumed it was available
Dan Harrin
Dan Harrin2y ago
yeah, but not quite
Prodex
ProdexOP2y ago
Works, thank you 🙏 Is ->action(fn() => '') the right way for a "view only" modal? Because I still get the submit + cancel button and only need a close button.
Dan Harrin
Dan Harrin2y ago
you can use ViewAction::make( instead of Action::make(
Prodex
ProdexOP2y ago
okay, but then I also get all disabled form elements. I would like to just have my custom view rendered inside the modal.
Dan Harrin
Dan Harrin2y ago
you have form elements but no action? how are you supposed to submit the form without a submit button
Prodex
ProdexOP2y ago
I think you got me wrong. I've a IncidentResource and everything works just fine with it. The only thing I want to do differently is to have a ViewAction where I can customize the content of it. Because the default disabled form elements don't quite fit for this use case.
Dan Harrin
Dan Harrin2y ago
oh ok just pass ->form([])
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Dan Harrin
Dan Harrin2y ago
it is not and what you have there is probably going to cause problems
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Dan Harrin
Dan Harrin2y ago
have you tried filters or actions in the nested table
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Dan Harrin
Dan Harrin2y ago
yes, check the docs
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Dan Harrin
Dan Harrin2y ago
no i dont mean that i mean you can open a modal by clicking on the content of any cell
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Dan Harrin
Dan Harrin2y ago
you can use an iconcolumn
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Dan Harrin
Dan Harrin2y ago
how about adding the action to the id column and instead of using a textcolumn, use a viewcolumn where you render the state and the icon together
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server