fix(ui): unnest action forms so Finalizar/Remover actually work (v1.38.6) - #70
Merged
Conversation
…8.6) The "Finalizar Spool" button on the spool edit page submitted the edit form instead of the deactivate route: it flashed "Rolo atualizado" and left the spool active. Same defect hit the admin-only "Remover" button on the filament edit page. Root cause: both action forms were written inside the edit form. HTML5 forbids nested forms, so the browser parser drops the inner <form> tag and the submit button is reassigned to the outer form. This also killed the data-sc-confirm dialog, since the form carrying the attribute never existed in the DOM. Finalizing from the spool list was never affected (there the form is a sibling, not nested). Fix: move each action form out of the edit form and bind the button with the HTML5 form attribute, keeping the button in place in the flex row (ms-auto migrates from the form to the button). csrf.js still injects the token, as it does for every POST form. Adds tests/test_nested_form.py, which parses the rendered HTML and fails if any form is nested — a route-level test cannot catch this, since the routes were always correct. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
Clicking "Finalizar Spool" on the spool edit page flashed "Rolo atualizado" and left the spool active — it saved the edit instead of finalizing. The
"Marcar spool como finalizado?"confirmation never appeared either.A sibling instance of the same defect: the admin-only "Remover" button on the filament edit page saved the filament instead of deleting it, also without confirmation.
Root cause
Both action forms were written inside the edit form. HTML5 forbids nested forms, so the browser parser discards the inner
<form>tag and reassigns itstype="submit"button to the outer form. The POST therefore went to the edit route.That also explains the missing confirmation: the
submitlistener instatic/spool.js:24readsdata-sc-confirmoffe.target, and the form carrying the attribute did not exist in the DOM.Finalizing from the spool list (
templates/spools/list.html:106) was never affected — there the form is a sibling, not nested. That working path is what confirmed the backend was fine:routes/spools.py:193-198anddatabase.py:818-821needed no change.The fix
Each action form moves out of the edit form and the button binds to it via the HTML5
formattribute, so the button stays exactly where it was in the flex row. Thems-autoright-alignment migrates from the form to the button.static/csrf.jskeeps injecting the token, as it does for every POST form.Tests
New
tests/test_nested_form.py(9 tests) parses the rendered HTML and fails on any nested form. A route-level test cannot catch this class of bug, since the routes were always correct — so the suite grows a check at the layer that actually broke.Verified the regression tests fail without the template fix (6 of the 9 go red) and pass with it. Full suite: 196 passed.
🤖 Generated with Claude Code