Skip to content

Commit

Permalink
users table bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
akechi17 committed Aug 10, 2024
1 parent 7b2119f commit 3568f89
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion resources/js/composable/useDeleteButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function useDeleteButton({ buttonId }) {
})
.then((value) => {
if (value) {
$(`#${buttonId}`).closest("form").trigger("submit");
$(`#${buttonId}`).closest("form").trigger('submit');
}
});
}
22 changes: 14 additions & 8 deletions resources/views/components/table.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,18 @@ class="header-function d-flex align-items-center @if ($routeCreate) justify-con
@once
@push('scripts')
<script type="module">
$('.button-delete').on('click', function() {
const buttonId = $(this).attr('id');
utils.useDeleteButton({
buttonId: buttonId
// Function to attach event handlers
function attachEventHandlers() {
$('.button-delete').off('click').on('click', function() {
const buttonId = $(this).attr('id');
utils.useDeleteButton({
buttonId: buttonId
});
});
})
}
// Initial event handler attachment
attachEventHandlers();
// Add event listener for search input
$('#search-input').on('input', function() {
Expand All @@ -89,10 +94,11 @@ class="header-function d-flex align-items-center @if ($routeCreate) justify-con
if (newPagination) {
document.querySelector('.pagination').innerHTML = newPagination.innerHTML;
}
// Reattach event handlers after content update
attachEventHandlers();
});
});
</script>
@endpush


@endonce

2 changes: 1 addition & 1 deletion resources/views/users/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class="bi bi-{{ $user->status == 1 ? 'x-circle' : 'check-circle' }}"></i></butto
<form action="{{ route('users.destroy', encrypt($user->id)) }}" method="POST" class="m-0">
@csrf
@method('DELETE')
<button id="button-{{ $user->id }}" class="button-delete btn btn-danger text-xs ms-1"
<button id="delete-button-{{ $user->id }}" class="button-delete btn btn-danger text-xs ms-1"
data-bs-toggle="tooltip" data-bs-placement="bottom" title="Delete" type="button"><i
class="bi bi-trash"></i></button>
</form>
Expand Down

0 comments on commit 3568f89

Please sign in to comment.