Form Validation inside Action
Hi, I'm trying to add a simple form validation inside my 'delete action'.
I want to show a random number and the user to introduce the same to delete the record.
I've tried changing the modal view, but it justs keeps dee¡leting everything no matter the form: <
Tables\Actions\Action::make('Delete')
->label('Eliminar')
->color('danger')
->modalContent(fn (Pedido $record,): View => view(
'filament.actions.deletePedido',
['record' => $record, 'aleatorio' => rand(1000, 9999)],
))
->modalSubmitActionLabel('Eliminar')
->modalCancelActionLabel('Cancelar')
->color('danger')
->action(function (Pedido $record, Request $request) {
$userNum = $request->input('userNum');
error_log($userNum."el del susuario");
$aleatorio = $request->input('aleatorio');
error_log($aleatorio."el del susuario");
if ($userNum === $aleatorio) {
error_log("Se borra");
}
else{
error_log(" No Se borra");
}
})>
10 Replies
maybe this can nudge you in the correct direction
Looks good, Bu in the end I used the form of the actions, then a new Blade, and rewrite the action() But thanks a lot
🙂 in the example you can see that you didn't need a seperate view to make it happen 😉
I've tried it but the ValidationException is not showing anything. It justs does nothing if the secretcode is wrong
you could change it to mountedActionsData.code
should display a message
still nothing , it justs stops charging and that's it
strange I'm seeing this
are you using my example or did you put the ValidationException in your code... in that case using 'code' => 'message' would be enough
which import of Actions are you using? I'm using Tables\Actions\DeleteAction
That's it, in the Table Actions does not works but in normal Filament Actions it does. don't know why
🙂