Files
railsgoat/app/views/admin/get_user.html.erb
T
Ken Johnson b4c6f93f68 Add debugging and fix form field attributes in admin modal
- Add console logging to openEditModal function to debug AJAX load
- Add explicit id and name attributes to admin select field
- Only show modal after content successfully loads
- Log errors if modal content fails to load

This helps diagnose the modal loading issue and fixes the Chrome
warning about form fields lacking id/name attributes.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-07 21:54:46 +00:00

95 lines
3.0 KiB
Plaintext
Executable File

<!-- Begin Modal -->
<div class="modal-header">
<h5 class="modal-title" id="myModalLabel1">
Account Settings
</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<%= form_for @user, :html => {:id => "account_edit"} do |f| %>
<div class="mb-3">
<%= f.label :email, nil, {:class => "form-label"}%>
<%= f.text_field :email, {:class => "form-control"}%>
</div>
<div class="mb-3">
<%= f.label :first_name, nil, {:class => "form-label"}%>
<%= f.text_field :first_name, {:class => "form-control"} %>
</div>
<div class="mb-3">
<%= f.label :last_name, nil, {:class => "form-label"}%>
<%= f.text_field :last_name, {:class => "form-control"} %>
</div>
<div class="mb-3">
<%= f.label :password, nil, {:class => "form-label"}%>
<%= f.password_field :password, {:class => "form-control", :placeholder => "Enter Password"}%>
</div>
<div class="mb-3">
<%= f.label :password_confirmation, nil, {:class => "form-label"}%>
<%= f.password_field :password_confirmation, {:class => "form-control", :placeholder => "Enter Password"} %>
</div>
<div class="mb-3">
<%= f.label :admin, nil, {:class => "form-label"}%>
<%= f.select(:admin, @admin_select, {}, {:class => "form-select", :id => "user_admin", :name => "user[admin]"}) %>
</div>
</div>
<div class="modal-footer">
<%= link_to "Delete", "#", {:id => "delete_button", :class => "btn btn-danger"} %>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<%= f.submit "Submit", {:id => 'submit_button', :class => "btn btn-primary"} %>
</div>
<% end %>
<!-- End Modal -->
<%= javascript_include_tag ('validation.js')%>
<script type="text/javascript">
$('#submit_button').click(function(e) {
e.preventDefault();
var valuesToSubmit = $("#account_edit").serialize();
var modalElement = document.getElementById('editAcct');
var modal = bootstrap.Modal.getInstance(modalElement);
modal.hide();
$.ajax({
url: "/admin/" + <%= @user.id %> + "/update_user.json",
data: valuesToSubmit,
type: "POST",
success: function(response) {
$('#success').show(500).delay(1500).fadeOut();
loadTable();
},
error: function(event) {
$('#failure').show(500).delay(1500).fadeOut();
}
});
});
$('#delete_button').click(function(e) {
e.preventDefault();
var modalElement = document.getElementById('editAcct');
var modal = bootstrap.Modal.getInstance(modalElement);
modal.hide();
$.ajax({
url: "/admin/" + <%= params[:admin_id] %> + "/delete_user.json",
type: "POST",
success: function(response) {
$('#success').show(500).delay(1500).fadeOut();
loadTable();
},
error: function(event) {
$('#failure').show(500).delay(1500).fadeOut();
}
});
});
</script>