F
Filament14mo ago
Prodex

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
awcodes14mo 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
Prodex14mo 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 Koch14mo ago
You can just use Action::make()->modalContent()
awcodes
awcodes14mo ago
Yes, the Action class support modals out of the box.
Prodex
Prodex14mo 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
toeknee14mo ago
You need an ->action()
Prodex
Prodex14mo ago
yes, but ->action() needs a callback and as I said above this should only display information of the record
toeknee
toeknee14mo 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
Prodex14mo ago
ah okay, and how can I access the $record inside the modal view?
toeknee
toeknee14mo 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
Prodex14mo ago
okay, sorry for my noob questions but you mean inline php inside blade? so {{ $evaluate(fn ($get) => $get('my_field')) }}
toeknee
toeknee14mo 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
Prodex14mo 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 Harrin14mo ago
->modalContent(fn ($record) => view('filament.modals.view-incident', ['record' => $record])) evaluation only works in things like form fields and table columns
toeknee
toeknee14mo ago
An action has a form? So assumed it was available
Dan Harrin
Dan Harrin14mo ago
yeah, but not quite
Prodex
Prodex14mo 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 Harrin14mo ago
you can use ViewAction::make( instead of Action::make(
Prodex
Prodex14mo 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 Harrin14mo ago
you have form elements but no action? how are you supposed to submit the form without a submit button
Prodex
Prodex14mo 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 Harrin14mo ago
oh ok just pass ->form([])
Unknown User
Unknown User14mo ago
Message Not Public
Sign In & Join Server To View
Dan Harrin
Dan Harrin14mo ago
it is not and what you have there is probably going to cause problems
Unknown User
Unknown User14mo ago
Message Not Public
Sign In & Join Server To View
Dan Harrin
Dan Harrin14mo ago
have you tried filters or actions in the nested table
Unknown User
Unknown User14mo ago
Message Not Public
Sign In & Join Server To View
Dan Harrin
Dan Harrin14mo ago
yes, check the docs
Unknown User
Unknown User14mo ago
Message Not Public
Sign In & Join Server To View
Dan Harrin
Dan Harrin14mo ago
no i dont mean that i mean you can open a modal by clicking on the content of any cell
Unknown User
Unknown User14mo ago
Message Not Public
Sign In & Join Server To View
Dan Harrin
Dan Harrin14mo ago
you can use an iconcolumn
Unknown User
Unknown User14mo ago
Message Not Public
Sign In & Join Server To View
Dan Harrin
Dan Harrin14mo 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 User14mo ago
Message Not Public
Sign In & Join Server To View