fix: update user fields full_name, administrator, password in UI#2701
fix: update user fields full_name, administrator, password in UI#2701crivetimihai merged 1 commit intomainfrom
Conversation
mcpgateway/admin.py
Outdated
| @@ -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"> | |||
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
Good point! I removed hx-swap="none", and I can also see the success notification message.
mcpgateway/admin.py
Outdated
| @@ -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" | |||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; }" | |||
There was a problem hiding this comment.
Nice work here replacing the event listener with a htmx call! 👏
gcgoncalves
left a comment
There was a problem hiding this comment.
Tested locally, submitting the for works and the success message is displayed correctly.
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>
a9d0682 to
601f322
Compare
…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>
🐛 Bug-fix PR
Relates: #2693
📌 Summary
Unable to update Users via Admin UI on the
Userspage. Errorhtmx:targetErroris logged to the browser console after hittingCancelor Update User` buttons in the Edit User modal.🔁 Reproduction Steps
Create a user without admin privileges.
Navigate to the Edit User page.
Modify any of the following:
Click on the
Update Userbutton and observe. The user details are not updated.Open the browser console and try to Edit the user again
Observe - the error
htmx:targetErroris logged to the browser console, and noUpdate usermodal 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
- Changed form from
hx-target="#user-edit-modal-content"tohx-swap="none"mcpgateway/templates/users_partial.html (1 change)
- Added inline event handler to Edit button
hx-on::before-requestto show modal synchronously before HTMX requesthx-swap="innerHTML show:top"for proper content swappingvoid modal.offsetHeightto ensure target is accessiblemcpgateway/templates/admin.html (1 change)
- Added
htmx:targetErrorevent listenerhx-swap="none"still triggers target lookupmcpgateway/static/admin.js (1 change)
- Removed redundant global
htmx:beforeRequestlistenerSolution 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
make lint-webmake testmake coverage📐 MCP Compliance (if relevant)
✅ Checklist
make black isort pre-commit)