Skip to content

CSS: style property page: Remove form elements from examples#44346

Open
ferdnyc wants to merge 1 commit into
mdn:mainfrom
ferdnyc:patch-1
Open

CSS: style property page: Remove form elements from examples#44346
ferdnyc wants to merge 1 commit into
mdn:mainfrom
ferdnyc:patch-1

Conversation

@ferdnyc
Copy link
Copy Markdown
Contributor

@ferdnyc ferdnyc commented Jun 3, 2026

Description

Remove <form> elements from around <button>s in example HTML code.

Motivation

Having <button> elements with id attributes in an example's HTML code will break if they are inside a <form> element, because in addition to running the bound click event handler, clicking the button will also attempt to submit the form,

This then results in a "400 Bad Request" error response from the playground runner.html page, and the rendered demo promptly vanishes.

Additional details

There's no need for the <form> elements anyway, as <button> elements with event handlers bound to respond to click events are functional on their own.

Note that only one of these examples was actually affected. (The second one didn't have an id attribute on the <button> element, so the form would not submit when clicked.) Nevertheless, I chose to remove the <form> from both examples, because it still amounts to superfluous and unnecessary noise. Examples should be minimal for clarity.

Related issues and pull requests

Having `<button>` elements with `id` attributes in an
example's HTML code will break if they are inside a
`<form>` element, because in addition to running the
bound `click` event handler, clicking the button will
also attempt to submit the form,

This then results in a "400 Bad Request" error response
from the playground `runner.html` page, and the
rendered demo promptly vanishes.

There's no need for the `<form>` elements anyway, as
`<button>` elements with event handlers bound to
respond to `click` events are functional on their own.
@ferdnyc ferdnyc requested a review from a team as a code owner June 3, 2026 19:24
@ferdnyc ferdnyc requested review from chrisdavidmills and removed request for a team June 3, 2026 19:24
@github-actions github-actions Bot added Content:WebAPI Web API docs size/s [PR only] 6-50 LoC changed labels Jun 3, 2026
@ferdnyc
Copy link
Copy Markdown
Contributor Author

ferdnyc commented Jun 3, 2026

Part of me thinks I should scan the rest of the repo for similarly-breakable HTML in examples on other pages, as this may be a more widespread issue than just two examples on this one page.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 3, 2026

Preview URLs (1 page)

@ferdnyc
Copy link
Copy Markdown
Contributor Author

ferdnyc commented Jun 3, 2026

Hmm, yes arguably https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event suffers from the same issue. The input field does demonstrate the beforeunload functionality properly. But because the form is submittable, it can break if navigation is triggered.

If you enter some text into the input field, then press Enter, the unsaved-changes alert will be shown. Clicking "Leave" will then cause the example to crash (rendered output disappears), because "Leave" amounts to approving the bad form submission.

I'll open an issue for this as a general site-wide concern, though this PR still fixes one of (possibly many) instances of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Content:WebAPI Web API docs size/s [PR only] 6-50 LoC changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants