
Substituting JavaScript with HTML - nartin
https://www.codementor.io/kwasiamantin/undefined-cmglhfnfv
======
linopolus
Coolest thing is: You can do completely without JS:

    
    
        <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..

~~~
foxhop
I was thinking this too. Forms never _needed_ Javascript to post. It's always
worked this way. Am I missing something?

~~~
GoToRO
Form validation.

~~~
krapp
Form validation doesn't need to be done in Javascript. I'd argue that it
_shouldn 't ever_ be done in Javascript, because that means implicitly
trusting the client, which is always a bad idea.

Since any sane application revalidates the response on the server anyway,
client side validation is just a gimmick, it's not necessary.

~~~
untog
> client side validation is just a gimmick

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.

~~~
studio_monolith
What is ajax

~~~
Zecc
> What is ajax

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.

------
denisw
It seems as if the author is on the way to rediscovering the idea of
Unobtrusive JavaScript, aka the RSJS pattern (Reasonable System for
JavaScript):

[http://ricostacruz.com/rsjs/](http://ricostacruz.com/rsjs/)

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...](http://guides.rubyonrails.org/working_with_javascript_in_rails.html)

~~~
SwellJoe
The article mentions Unobtrusive JavaScript toward the end:

"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."

------
andrewmcwatters
HTML valid and semantic markup:

    
    
      <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!

------
hacknat
I do have to say that it has been really annoying to watch my front end team
miss deadlines to keep up with Angular versions. They also seem to introduce
pretty basic bugs. What annoys me the most is there no reason for our product
to have be a fancy SPA, it would be just as useful if it were a static site.
The most complicated form element we have is a number input and a Stripe GUI.
We also have a user facing cli tool that receives little UX love from them,
because they don't understand how it works. Ironically, the cli generates
about 2/3s of our users requests.

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.

~~~
repsilat
> _there no reason for our product to have be a fancy SPA, it would be just as
> useful if it were a static site._

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."

------
dingdingdang
Wait what.. ends with: "So now the JS library listens on the special classes
and acts accordingly. This as opposed to what we had earlier is that now for N
number of times we work with data from the backend the JS code responsible for
it is the same. So for instance if you compare JQuery to Bootstrap. whereas
you write some amount of JS to use J [cut-off]".

Surely this is just re-factored JS then?!

~~~
oceanswave
Looks like a micro framework that changes the server resource that the form
posts to based on css classes

------
stevebmark
What? This is _terrible._ This introduces an "API":

    
    
        <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.

------
clishem
Interesting that the images on that website don't load without Javascript. If
only there was a way to show images with HTML instead of Javascript.

------
z3t4
It's nice that forms work without JavaScript. Maybe we should make more stuff
work without JavaScript too !? Maybe an option to bind HTML to program state,
automatically updating the element's values when the state changes for example
from a web socket message, or user click, but without the help from
JavaScript.

~~~
tzahola
Mind = blown! Wow! Just, wow!

------
city41
Why not use data attributes instead of classes? This is one of their intended
use cases.

~~~
curyous
Data attributes seem like the right way to me.

------
j_s
Minimum viable JavaScript SPA:

[http://intercoolerjs.org/](http://intercoolerjs.org/)

------
detaro
Clickbaity title due to not making clear that it is purely about the interface
to the library.

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...](https://www.smashingmagazine.com/2017/02/designing-html-apis/)

List of examples [http://markapp.io/](http://markapp.io/)

------
vcanales
This is 'interesting', but I don't see it as useful at all. And it's not a
substitution of JS, but rather of how you interface with it.

------
Narretz
Hm, this sounds suspiciously what AngularJS (and I assume other projects too)
did as early as 2011 - apply the Javascript logic via template / attributes
instead of fetching elements via Javascript and applying logic.

------
cdevs
I've mentioned it before but I had a "aha" moment when I found intercooler js,
it would be awesome to have 3-5 JavaScript functions instead of always
rewriting and building Ajax request. Only problem with intercooler is it
expects HTML in return instead of json.

------
_pdp_
Many web applications are data-entry centric so yes use more HTML and use less
JavaScript because forms are builtin. However, for anything that goes beyond
this, JavaScript is not just an option - it is a must. You can avoid it but
you will also not going to create anything interesting.

------
watersb
I can no longer tell if the cool kids are joking or not.

