3 ms·
HTML is just the language for describing the page content. It's not designed to be dynamic. A modern JS component library could have support for something like
by kypro 3y ago
HTML is just the language for describing the page content. It's not designed to be dynamic. A modern JS component library could have support for something like this.
The author's suggestion of using a data attribute instead of adding a disabled class to the element and the styling of it is more of preference thing.
That said, I don't really understand why there isn't something like a "singleSubmit" attribute you can add to a HTML form to automatically disable duplicate submissions. Handling double form submits is a frequent problem – you almost never want a form to be immediately resubmitable which HTML forms are.
- pavlov 3y agoYour comment is a good example of the peculiar cognitive dissonance that surrounds HTML. The first reaction is always defensive, "HTML isn't designed for this!" — and two paragraphs later it's: "HTML should really do this though".
- wzdd 3y agoI didn't see this as cognitive dissonance. It is "HTML and CSS are declarative. It would be good if there were a way to specify this requirement declaratively."
- kypro 3y agoTo clarify, I don't think HTML should be expected to be responsible for button styling – that is a CSS concern. But I was really more responding to the "why can't I do this with a HTML library" comment, which you can but with a JS library instead. And while it's true HTML has some dynamic elements the assertion that you should be able to build advanced dynamic behaviour like this in HTML alone I think misunderstands the purpose of HTML. JS was built for more advanced dynamic behaviour, and you can absolutely do what the parent commenter is asking for with a JS library. To defend my suggestion of a "singleSubmit" attribute – I think the form element itself which already has the ability to do some basic dynamic stuff like submit a form in various ways could reasonably include the basic requirement of not allowing said form to be submitted twice. Personally this isn't something I think is a huge issue because most of the time when we'd want to do this we're looking to build fancy dynamic form behaviour anyway and in those cases JS is going to be what you need to use for that. But there are some simple webpages out there which don't care about any of that fancy stuff and literally just want a form on a page which POSTs data to another page, and in those cases it would be nice to have the "singleSubmit" attribute I suggested.
- wongarsu 3y agoForms are one of the rare instances where "dynamic" content was actually designed into HTML. Sure, the original intention was to have a page transition on form submission, but for the user that might be indistuinishable from what JavaScript is doing today. A much better behavior would be to have the form handle the button state automatically: once you submit the form, all submit buttons of the form are disabled until the completion the button's onclick handler, the form's onsubmit handler, and any request triggered by the form action. Once all of these are done, all submit buttons belonging to this form are automatically enabled again. If you want to get fancy, HTML could have introduced a fifth button state for this to make it distinct from a "normal" disabled button, and maybe allowed the form to change the button content for that state (you might want the button to say "please wait" or "loading"). But really, just simple sane handling of the disabled state would have been so much better than the barebones forms we have. Make it overridable by an attribute if you really want to support the edge case of a form having intentional concurrent submissions.
- thaumasiotes 3y ago> That said, I don't really understand why there isn't something like a "singleSubmit" attribute you can add to a HTML form to automatically disable duplicate submissions. Handling double form submits is a frequent problem – you almost never want a form to be immediately resubmit[t]able which HTML forms are. I assume because submitting a form takes you to a different page, where the form no longer exists.
- foobarchu 3y agoThis problem is bigger than JavaScript and dynamic applications. Even decades ago you'd see warnings to "please only click submit once", because most users don't look at the browser activity state to see if it is actually doing something (regardless of it being an spa or classic pages). There needs to be two kinds of forms, one that asks if you really want to re-submit, and another that allows infinite submission. The backend should handle the problem too, but this would go a long way toward a better default UX.
- akira2501 3y ago> I don't really understand why there isn't something like a "singleSubmit" attribute addEventListener has a 'once' option that will only fire the event once. If you're willing to handle all the error cases, it seems like the easiest option.