Interestingly, if we remove the whole ->modalContent thing, the form is validating correctly.
Filament 3 - Issue with form validation (Validating a form before performing form's Modal Action)
How do I validate a form before displaying a modal using a form Action? ->before, ->action and ->mountUsing doesn't work.
The goal here is to grab the current form's state without saving it to the database, generate a Pdf from it and output it into the modal content so that the user can see the generated pdf preview right away, without downloading it - and it's already working.
The problem is that the form isn't validated before the action is performed. How do I fix that?
I tried adding these things but it doesn't work, the form still isn't validated before the modal is shown. The code inside isn't even being ran before the modal is shown:
->before(function ($livewire) {
$livewire->validate();
})
->action(function ($livewire) {
$livewire->validate();
})
->mountUsing(function ($livewire) {
$livewire->validate();
})
Here's the code that's inside of the resource's form:
Forms\Components\Actions::make([
Forms\Components\Actions\Action::make('preview')
->label('Preview')
->icon('heroicon-m-eye')
->modalContent(function (Get $get) {
$pdf_transformer = new FormDataToPdf($get);
$pdf = $pdf_transformer->getPdf();
return view('modalpreview', [
'pdf_content' => base64_encode($pdf->output())
]);
})
->modalSubmitAction(false)
->modalCancelAction(false)
])
I tried:
Forms\Components\Actions::make([
Forms\Components\Actions\Action::make('preview')
->label('Preview')
->icon('heroicon-m-eye')
->before(function ($livewire) {
$livewire->validate();
})
->modalContent(function (Get $get) {
$pdf_transformer = new FormDataToPdf($get);
$pdf = $pdf_transformer->getPdf();
return view('modalpreview', [
'pdf_content' => base64_encode($pdf->output())
]);
})
->modalSubmitAction(false)
->modalCancelAction(false)
])
Please or to participate in this conversation.