In the project, we used laravel livewire. In index, there's a button where when the user clicked the button it will open a modal.
Where the modal is for the confirmation before deleting the records, I used javascript/jquery to pass the id in the hidden input field but now I'm having a trouble to pass the id in my component
Question: How do I pass the data inside of preConfirm method of sweetalert 2?
Javascript
if ( $('form#delete-data-form').length > 0 ) {
$('div').on('submit', 'form#delete-data-form', function(e){
var id = $('input[name="module_id"]').val();
var module_name = getMonth(id);
Swal.fire({
title: 'Are you sure?',
text: "you want to delete all the data of "+module_name+"?",
icon: 'warning',
showCancelButton: true,
confirmButtonText: 'Delete',
cancelButtonText : 'Cancel',
allowOutsideClick: () => !Swal.isLoading(),
preConfirm: function(result) {
if (result) {
var name = @this.call('deleteData',id).then(() => {
Swal.fire('Loading complete');
});
}
},
});
e.preventDefault();
return false;
})
}