Files
railsgoat/app/views/admin/get_all_users.html.erb
T
Ken Johnson 844acfc8e6 Use proper Bootstrap 5 native modal API with initialization
Bootstrap 5 removed jQuery plugin support, so .modal('show') doesn't work.
Switch back to native Bootstrap 5 Modal API with proper initialization:

- Dispose of any existing modal instance before creating new one
- Create modal with explicit options (backdrop, keyboard, focus)
- Add detailed console logging for each step

This ensures the modal is properly initialized before showing.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-07 22:16:24 +00:00

92 lines
2.5 KiB
Plaintext
Executable File

<div id="dt_example" class="example_alt_pagination">
<table class="table table-striped table-hover table-bordered pull-left" id="data-table">
<thead>
<tr>
<th>
Name
</th>
<th>
Email
</th>
<th>
Admin User
</th>
<th>
Action
</th>
</tr>
</thead>
<tbody>
<% @users.each do |u|%>
<tr>
<td style="word-wrap:break-word;">
<%= "#{u.first_name} #{u.last_name}"%>
</td>
<td>
<%= u.email%>
</td>
<td>
<%= u.admin ? %{<span class="fs1" aria-label="check" data-icon="&#xe0fe;"}.html_safe : nil %>
</td>
<td>
<%= link_to "Edit", "#", {:onClick => "javascript:openEditModal(#{u.id}); return false;", :role => "button", :style => "width:70px", :class => "btn btn-inverse"}%>
</td>
</tr>
<% end %>
</tbody>
</table>
<div id="editAcct" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel1" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<!-- Content will be loaded here dynamically -->
</div>
</div>
</div>
<div class="clearfix">
</div>
</div>
</div>
<script type="text/javascript">
function openEditModal(id){
var link = '/admin/'+ id +'/get_user';
console.log('Loading modal content from:', link);
$("#editAcct .modal-content").load(link, function(response, status, xhr) {
console.log('Load status:', status);
if (status == "success") {
console.log('Initializing Bootstrap 5 modal');
var modalEl = document.getElementById('editAcct');
// Ensure any existing instance is disposed
var existingModal = bootstrap.Modal.getInstance(modalEl);
if (existingModal) {
existingModal.dispose();
}
// Create new modal with options
var modal = new bootstrap.Modal(modalEl, {
backdrop: true,
keyboard: true,
focus: true
});
console.log('Modal created, calling show()');
modal.show();
console.log('Modal should be visible now');
} else {
console.error('Failed to load modal content:', xhr.statusText);
}
});
};
function dataTablePagination(){
$('#data-table').dataTable({
"sPaginationType": "full_numbers"
});
};
$(document).ready(dataTablePagination());
</script>