Substituting JavaScript with HTML
codementor.io
codementor.io
<form action="https://example.com/submit_foo" method="POST">
<input type="text" name="bar">
<input type="submit" value="Submit">
</form>
Browser handles sending, backend handles processing.Yes, blows my mind too..
Since any sane application revalidates the response on the server anyway, client side validation is just a gimmick, it's not necessary.
We create a worse user experience by waiting until the form is submitted to inform the user of some silly error.
For some applications, the difference isn't that big, but for many it brings a significant improvement.
Is it possible to create crappy client side validation? E.g. not letting the user temporarily input invalid data while filling out the form, or displaying over-the-top red error indicators everywhere as soon as a single mistake is made, etc... Definitely. But let's not throw the baby out with the bathwater.
The backend should never trust the client, of course. That is a separate goal of the application, however.
It absolutely shouldn't be done in Javascript only.
Server side validation requires a whole page round trip. The user will have to wait, lose their scroll position... you can't rely on client side validation only, but neither is it a gimmick.
Server-side validation relying on JavaScript. You still have to wait for the server to respond, and now you need to implement UI to tell the user something is happening in the background. But at least you can start proactively validating before the user actually submits the form, so there's that.
Also, there is the setting of HTTP headers which requires JavaScript.
<input type="hidden" name="_method" value="PATCH">The server has to support it.
I always wish I could ship something like that, and it does sometimes start out that way. But it never lasts, not anywhere that cares more about UX than they care about HTML purism.
The main difference is that Unobtrusive JavaScript relies on HTML5 data attributes rather than misusing CSS classes.
Perhaps the most well-known example of the Unobtrusive JavaScript approach are the AJAX helpers of Rails:
http://guides.rubyonrails.org/working_with_javascript_in_rai...
"With the addition of classes I can enjoy all the custom CSS Bootstrap provides for the most part of what we need as far as styling goes . Why can’t we have same for JS ? It turns out we actually do and such libraries are known as UnObstrusive JS libs."
<form action="https://formspree.io/your@email.com"
method="POST">
<input type="text" name="name">
<input type="email" name="_replyto">
<input type="submit" value="Send">
</form>
Indirect FormData manipulation, misuse of `class`, ignorance of dataset: <form class="dv-add-oneto:profiles:details"> <input type="text" name="firstname" placeholder="Please enter your first name"><br> <input type="text" name="lastname" placeholder="Please enter your last name"><br> <input type="number" name="age" placeholder="Please enter your age"><br> <button type="submit">Submit</button></form>
Yep! Sounds good to me!I realize that fancy JS applications need to exist in certain contexts. I just think the vast majority of SPAs out there are clumsy, unjustifiable monstrosities, because..."we have to have an awesome front end, right?"
I want to be clear that I'm talking about product front ends, not marketing sites or the like.
So common, so true, but certainly an argument you'll never win.
> the cli generates about 2/3s of our users requests
This is more interesting, I think -- is that widely known internally? Is that number growing or shrinking? Do users start on the web interface and migrate to the CLI, or do they pick one and stick with it? Do they use the CLI by hand, or do they have scripts to make the interface better?
The whiz-bang web interface may drive sales better, but improving the way the product is used will drive retention. Try to stay positive about it, and keep a wide perspective, but do make sure that what you know and what you think are known "up the chain."
Surely this is just re-factored JS then?!
<form class="dv-add-oneto:profiles:details">
Which is handled by...Javascript! And now you have a nasty mini string language API, like Angular.We have portable, functional components. It's called React. Embedding view logic in class names is the wrong way.
These home grown solutions are what we used to do as front end developers before React. Now we write portable component code.
Lea Verou called an interface like this "HTML API", which standing alone also is missing the script context but is at least clear in that it is about the API, not the entire code: https://www.smashingmagazine.com/2017/02/designing-html-apis...
List of examples http://markapp.io/