CSS: style property page: Remove form elements from examples#44346
CSS: style property page: Remove form elements from examples#44346ferdnyc wants to merge 1 commit into
Conversation
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.
|
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. |
|
Preview URLs (1 page) |
|
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 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. |
Description
Remove
<form>elements from around<button>s in example HTML code.Motivation
Having
<button>elements withidattributes in an example's HTML code will break if they are inside a<form>element, because in addition to running the boundclickevent 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.htmlpage, 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 toclickevents are functional on their own.Note that only one of these examples was actually affected. (The second one didn't have an
idattribute 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