I’m no longer using Bootstrap for open and close modals. For example, in table for each row with buttons to edit and delete I make this:
<button wire:click="selectItem({{ $property->id }}, 'update')" class="btn btn-light-secondary"
data-placement="top" title="Edit"> </button>
<button wire:click="selectItem({{ $property->id }}, 'delete')" class="btn btn-light-secondary"
data-placement="top" title="Delete"> </button>
In the component:
public function selectItem($itemId, $action)
{
if ($action == 'delete') {
$this->dispatchBrowserEvent('openDeleteModal');
}
else {
$this->emit('getUserModelId', $itemId);
$this->dispatchBrowserEvent('openFormModal');
}
}
and in parent blade component or in scripts section:
window.addEventListener('openFormModal', event => {
$("#formModal").modal('show');
})
window.addEventListener('closeFormModal', event => {
$("#formModal").modal('hide');
})
window.addEventListener('openDeleteModal', event => {
$("#deleteModal").modal('show');
})
window.addEventListener('closeDeleteModal', event => {
$("#deleteModal").modal('hide');
})
The Delete modal is like this:
<!-- Delete Modal -->
<div class="modal fade" id="deleteModal" tabindex="-1" aria-labelledby="deleteModalLabel" aria-hidden="true" data-keyboard="false" data-backdrop="static">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="deleteModalLabel">Delete User</h5>
<button type="button" class="close" wire:click="closeDeleteModal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<h3>Are you sure?</h3>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" wire:click="closeDeleteModal">Cancel</button>
<button type="button" class="btn btn-primary" wire:click="destroy">Yes</button>
</div>
</div>
</div>
</div>
and in destroy method first run the deletion action and after call to close the modal. I’m not sure in your case, but is good clean every var that was involved in here, for example the selected item. Hope you understand and like this can help you. I will be around for any cuestion