Tag form: empty Page Body returns a bare 400 Bad Request
Problem
The tag form (/tag/add) shows a "Page Body" field. The label says "Required field". The form does not enforce this in the browser. A patron can submit the form with an empty Page Body. The server then replies with a bare 400 Bad Request. The patron sees no message. The patron cannot tell what to fix.
The tag edit form (/tags/OL…T/edit) has the same problem.
Evidence:
- The textarea
#page_bodyhas norequiredattribute:openlibrary/templates/type/tag/tag_form_inputs.html(line 45). - The server rejects an empty body and raises
web.badrequest():openlibrary/plugins/upstream/addtag.py(validate_tagat line 41, the check at line 131 for add, and line 186 for edit).
The form uses the TipTap editor (<ol-markdown-editor>). TipTap writes the content to a contenteditable div. It hides the real textarea with display: none (openlibrary/components/lit/OLMarkdownEditor.js, line 506). Because of this, a plain required attribute will not work well. A display: none control cannot show the browser validation message. Chrome logs the error An invalid form control with name='body' is not focusable and shows nothing.
So the issue has two parts:
- The form does not block an empty Page Body before submit.
- The fix is not simple, because the visible input is TipTap, not a native form control.
Reproducing the bug
Add a tag:
- Log in as a curator or admin.
- Go to
/tag/add. - Fill Tag Name, Tag Type, and Tag Description.
- Leave Page Body empty.
- Submit the form.
Edit a tag:
- Go to
/tags/OL…T/editfor an existing tag. - Clear the Page Body field.
- Submit the form.
- Expected behavior: The page shows a clear message. For example: "Please fill out this field."
- Actual behavior: The server returns
400 Bad Request. The page shows no message.
Context
- Browser: Firefox 157
- OS: Mac
- Logged in (Y/N): Y
- Environment (prod, dev, local): local
Breakdown
Implementation Details (for maintainers)
A maintainer must choose the approach. Two directions are possible.
Option A: make ol-markdown-editor a form-associated custom element (FACE)
The repository already has FormAssociatedMixin (openlibrary/components/lit/utils/form-associated-mixin.js). It is used by OlToggle, OlSegmentedControl, and others.
Make the editor a FACE. Add a required property. Report validity with ElementInternals.setValidity(). Then the required attribute lives on <ol-markdown-editor> in the template. This approach works for every markdown field, not only this one.
One point to decide: the hidden textarea is the no-JS fallback. If the FACE owns submission, the textarea must not submit at the same time.
Option B: keep the textarea as the form control
Keep name="body" on the textarea. Add required. Listen for the invalid event on the textarea. Cancel the default behavior. Move focus to the editor. Show an inline message.
This approach is small. It keeps the no-JS fallback. But it is not reusable for the other markdown fields.
Requirements Checklist
- [ ] Choose the approach (A or B).
- [ ] Add a client-side message for an empty Page Body.
- [ ] Confirm that the server still rejects an empty body.
Related files
openlibrary/templates/type/tag/tag_form_inputs.htmlopenlibrary/plugins/upstream/addtag.pyopenlibrary/components/lit/OLMarkdownEditor.jsopenlibrary/components/lit/utils/form-associated-mixin.js
Stakeholders
@lokesh— please decide the approach.
Instructions for Contributors
- Please run these commands to ensure your repository is up to date before creating a new branch to work on this issue and each time after pushing code to Github, because the pre-commit bot may add commits to your PRs upstream.
Context
- Confirmed
#page_body(name="body") has norequiredattribute, while the other required fields in the same form do:name,tag_description, andtag_typeall carryrequired— onlybodyis missing it. https://github.com/internetarchive/openlibrary/blob/067040fea74027d74fe34a048cf4edf765cb554d/openlibrary/templates/type/tag/tag_form_inputs.html#L29-L46 - Confirmed server-side rejection:
validate_tag()requirestag.get("body")to be truthy, and bothaddtag.POSTandtag_edit.POSTraise a bareweb.badrequest()with no message on failure. https://github.com/internetarchive/openlibrary/blob/067040fea74027d74fe34a048cf4edf765cb554d/openlibrary/plugins/upstream/addtag.py#L40-L42 (check), https://github.com/internetarchive/openlibrary/blob/067040fea74027d74fe34a048cf4edf765cb554d/openlibrary/plugins/upstream/addtag.py#L131 (add), https://github.com/internetarchive/openlibrary/blob/067040fea74027d74fe34a048cf4edf765cb554d/openlibrary/plugins/upstream/addtag.py#L186 (edit) - Confirmed
<ol-markdown-editor>setsdisplay: noneon its target element, which is why a nativerequiredattribute on the textarea would not surface a usable validation message: https://github.com/internetarchive/openlibrary/blob/067040fea74027d74fe34a048cf4edf765cb554d/openlibrary/components/lit/OLMarkdownEditor.js#L506 FormAssociatedMixin(Option A's foundation) exists and is already consumed byOlToggle,OLButton,OlSegmentedControl,OlOptionsPopover, andOlSelectPopover. However, none of those consumers implementrequiredor callElementInternals.setValidity()— the mixin itself has no validity-reporting support today (nosetValidity/checkValidityhooks). Option A isn't "reuse an existing pattern," it's new groundwork on the mixin plus retrofittingOLMarkdownEditorto use it. https://github.com/internetarchive/openlibrary/blob/067040fea74027d74fe34a048cf4edf765cb554d/openlibrary/components/lit/utils/form-associated-mixin.js#L32-L45- The TipTap editor was introduced in #12182 ("Feature - New WYSIWYG editor via tiptap", merged 2026-04-29), which is the origin of the
display: nonetarget pattern this bug stems from. - No duplicate or prior attempt found searching issues/PRs for this specific gap.
Issue Assessment
Open questions
- [x] Does any existing Lit component already implement
required/validity reporting viaElementInternals, thatOLMarkdownEditorcould copy? (Answer: No — checked all five currentFormAssociatedMixinconsumers; none implementsetValidity/required. Option A requires adding this capability to the mixin itself, not just wiring up an existing one.)
Suggested breakdown
Needs: Breakdown applies — the existing checklist is "choose an approach, then implement it," not concrete steps for either option. Once @lokesh picks a direction:
- [ ] If Option A: add
required/validity-reporting support toFormAssociatedMixin(new capability, not reuse), then convertOLMarkdownEditorto a FACE and resolve the dual-submission concern with the hidden textarea (noted in the issue body). - [ ] If Option B: add
requiredto the#page_bodytextarea, wire aninvalidlistener that cancels default behavior, focuses the editor, and shows an inline message. - [ ] Either way: add/extend a test confirming the server still rejects an empty
body(validate_tag/addtag.pybehavior is correct today and shouldn't regress).
Given the explicit two-option fork requiring a maintainer's architectural call, neither sub-task is a Good First Issue until the approach is decided — Option B's isolated version could become one once chosen.
🔔 Stakeholders
@lokesh — the issue already asks you directly to choose between Option A and B; flagging since that decision is what's currently blocking a breakdown.
Full triage checklist
- [x] Triage — correct labels applied or removed (
Needs: Leadremoved sinceLead: @lokeshis already set;Needs: Staff Decisionadded) - [x] Problem / opportunity — problem is clear, audience identified, actionable
- [x] Scope — issue is well-scoped; does not try to do too many things
- [x] Justification — reasoning and impact stated; sufficient for leads to prioritize
- [x] Success & testing criteria — defines what "done" looks like, verifiable by a contributor
- [ ] Proposal & breakdown — two options outlined, but no concrete step list for either until a maintainer picks one
- [x] If bug: environment & repro steps — browser, OS, and step-by-step repro given for both add and edit forms
- [x] Risks, concerns, open questions — the dual-submission risk for Option A and the limited reusability of Option B are both already called out in the issue body
- [x] Richy context — relevant code, commits, PRs reviewed; no duplicate found
- [x] References — permalinks and file/line references present in the issue body itself
[!NOTE] This comment was automatically generated by Richy, Open Library's issue enrichment assistant, on behalf of @mekarpeles. This is NOT a sign-off. This issue needs lead review before work begins.
hi @RayBB can i work on this issue please if its open to external contributors?
Thanks for assigning this to me! @lokesh , before I start: are you OK with Option B, but implemented inside OLMarkdownEditor?
The editor would listen for invalid on its target textarea, cancel it, focus the editor, and show the textarea's validationMessage inline. Any required textarea paired with the editor gets this automatically, so it's reusable. It also keeps the no-JS fallback and needs no changes to FormAssociatedMixin.
I'd also add a test confirming the server still rejects an empty body. Should the server re-render the form with an error message instead of a bare 400, like it already does for duplicate slugs? Or should that be a separate issue?
@nilaychugh Yes, go ahead with Option B, implemented inside OLMarkdownEditor as you described. Thanks!