Skip to content

fix: update user fields full_name, administrator, password in UI#2701

Merged
crivetimihai merged 1 commit intomainfrom
2693-fix-update-users-in-ui
Feb 7, 2026
Merged

fix: update user fields full_name, administrator, password in UI#2701
crivetimihai merged 1 commit intomainfrom
2693-fix-update-users-in-ui

Conversation

@marekdano
Copy link
Copy Markdown
Collaborator

🐛 Bug-fix PR

Relates: #2693

📌 Summary

Unable to update Users via Admin UI on the Users page. Error htmx:targetError is logged to the browser console after hitting Cancel or Update User` buttons in the Edit User modal.

🔁 Reproduction Steps

  1. Create a user without admin privileges.

  2. Navigate to the Edit User page.

  3. Modify any of the following:

    • Administrator checkbox
    • Password
    • Full Name
  4. Click on the Update User button and observe. The user details are not updated.

  5. Open the browser console and try to Edit the user again

  6. Observe - the error htmx:targetError is logged to the browser console, and no Update user modal is not displayed again

🐞 Root Cause

The browser console was logging htmx:targetError
This occurred because HTMX was trying to swap content into a target element that was hidden or not yet visible.

💡 Fix Description

Files Modified

  1. mcpgateway/admin.py (2 changes)
    - Changed form from hx-target="#user-edit-modal-content" to hx-swap="none"
    • Prevents HTMX from swapping the success response after the modal closes
    • Modal closing is handled via HX-Trigger event (adminUserAction)
- Added `hx-swap="none"` to Cancel button
  - Prevents HTMX from attempting content swap when the modal is hidden
  1. mcpgateway/templates/users_partial.html (1 change)
    - Added inline event handler to Edit button

    • Added hx-on::before-request to show modal synchronously before HTMX request
    • Added hx-swap="innerHTML show:top" for proper content swapping
    • Forces browser reflow with void modal.offsetHeight to ensure target is accessible
  2. mcpgateway/templates/admin.html (1 change)
    - Added htmx:targetError event listener

    • Suppresses targetError for user edit modal operations
    • Necessary because hx-swap="none" still triggers target lookup
  3. mcpgateway/static/admin.js (1 change)
    - Removed redundant global htmx:beforeRequest listener

    • No longer needed since modal visibility is handled inline on the Edit button
    • Cleaner, more maintainable code

Solution Architecture

Before: Global event listeners checking every HTMX request
After: Inline event handler scoped to specific button + error suppression

Benefits
✅ No more console errors
✅ Modal opens/closes correctly every time
✅ Better performance (no global listeners)
✅ Follows HTMX best practices

Now, no errors are logged, and user details can be updated.

🧪 Verification

Check Command Status
Lint suite make lint-web
Unit tests make test
Coverage ≥ 80 % make coverage
Manual regression no longer fails steps / screenshots

📐 MCP Compliance (if relevant)

  • Matches current MCP spec
  • No breaking change to MCP clients

✅ Checklist

  • Code formatted (make black isort pre-commit)
  • No secrets/credentials committed

@@ -6128,7 +6128,7 @@ async def admin_get_user_edit(
edit_form = f"""
<div class="space-y-4">
<h3 class="text-lg font-semibold text-gray-900 dark:text-white mb-4">Edit User</h3>
<form hx-post="{root_path}/admin/users/{user_email}/update" hx-target="#user-edit-modal-content" class="space-y-4">
<form hx-post="{root_path}/admin/users/{user_email}/update" hx-swap="none" class="space-y-4">
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a conflict here with the changes on #2703. The hx-swap shouldn't be none, that id should be added to the wrapper above (line 6129).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! I removed hx-swap="none", and I can also see the success notification message.

@@ -6169,7 +6169,7 @@ async def admin_get_user_edit(
data-require-special="{'true' if settings.password_require_special else 'false'}"
></div>
<div class="flex justify-end space-x-3">
<button type="button" onclick="hideUserEditModal()"
<button type="button" onclick="hideUserEditModal()" hx-swap="none"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the changes listed in the comment above, hx-swap="none" is not needed. Also, without the swap, the success message is not displayed on updating the user.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! I removed hx-swap="none".

@@ -43,6 +43,8 @@ <h3 class="text-lg font-semibold text-gray-900 dark:text-white">{{ user.full_nam
class="px-3 py-1 text-sm font-medium text-blue-600 dark:text-blue-400 hover:text-blue-800 dark:hover:text-blue-300 border border-blue-300 dark:border-blue-600 hover:border-blue-500 dark:hover:border-blue-400 rounded-md focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500"
hx-get="{{ root_path }}/admin/users/{{ user.email | urlencode }}/edit"
hx-target="#user-edit-modal-content"
hx-swap="innerHTML show:top"
hx-on::before-request="const modal = document.getElementById('user-edit-modal'); if (modal) { modal.style.display = 'block'; modal.classList.remove('hidden'); void modal.offsetHeight; }"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work here replacing the event listener with a htmx call! 👏

@marekdano marekdano requested a review from gcgoncalves February 5, 2026 12:31
Copy link
Copy Markdown
Collaborator

@gcgoncalves gcgoncalves left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally, submitting the for works and the success message is displayed correctly.

@crivetimihai crivetimihai self-assigned this Feb 6, 2026
The Edit User modal was hidden when HTMX tried to swap content into
#user-edit-modal-content, causing htmx:targetError console errors.

Changes:
- Add hx-on::before-request to Edit button to show modal synchronously
- Remove global htmx:afterRequest listener that showed modal after request
- Remove hx-target from form since content swaps into modal while visible

The modal is now visible before HTMX requests, preventing targetError.

Closes #2693

Signed-off-by: Marek Dano <mk.dano@gmail.com>
Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
@crivetimihai crivetimihai force-pushed the 2693-fix-update-users-in-ui branch from a9d0682 to 601f322 Compare February 7, 2026 00:04
@crivetimihai crivetimihai merged commit a00b476 into main Feb 7, 2026
46 checks passed
@crivetimihai crivetimihai deleted the 2693-fix-update-users-in-ui branch February 7, 2026 00:05
kcostell06 pushed a commit to kcostell06/mcp-context-forge that referenced this pull request Feb 24, 2026
…BM#2701)

The Edit User modal was hidden when HTMX tried to swap content into
#user-edit-modal-content, causing htmx:targetError console errors.

Changes:
- Add hx-on::before-request to Edit button to show modal synchronously
- Remove global htmx:afterRequest listener that showed modal after request
- Remove hx-target from form since content swaps into modal while visible

The modal is now visible before HTMX requests, preventing targetError.

Closes IBM#2693

Signed-off-by: Marek Dano <mk.dano@gmail.com>
Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants