I'm trying to preventDefault a form made with Laravel Collective. The funny thing is that it works once and then it stops working. I'm working my js with Laravel Mix.
Here's my code:
// Here's the form in my blade
{!! Form::open(['class' => 'confirm-delete','method' => 'DELETE', 'route' => ['users.destroy', $user->id], 'data-title' => __('Delete User') ]) !!}
<button type="submit" class="dropdown-item" href="#" style="cursor: pointer"><i class="fas fa-trash-alt"></i> {{ __('Delete') }}</button>
{!! Form::close() !!}
// Here's my code in my js
$(".confirm-delete").submit(function (e) {
alert("It doesn't alert this D:");
var form = this;
e.preventDefault();
swal({
title: form.data("title"),
icon: "warning",
buttons: [
'No, cancel it!',
'Yes, I am sure!'
],
dangerMode: true,
}).then(function (isConfirm) {
if (isConfirm) {
form.submit();
}
});
});
I have tried with these links but none have worked:
https://stackoverflow.com/a/54062772/3675186
Using JQuery - preventing form from submitting
I'm working with Laravel 5.6.