News for hackers. Stuff that matters.
Re:Show HN: Help Me Decide Please by franciscop on Friday April 24, 2020 @09:01PM (#22974631)
Tip: if you input something and press "enter", it will reset the form. You should attach the event listener to the form's onSubmit, and not to the button's onClick.
Re:Show HN: Help Me Decide Please by joppy on Friday April 24, 2020 @10:36PM (#22975076)
Is there some book of best web dev practices where stuff like this is written down?
Re:Show HN: Help Me Decide Please by jmchuster on Saturday April 25, 2020 @06:11AM (#22977061)
You might notice by just using the web, or you might notice it when testing the form on one of your first assignments, that you can submit a form by pressing enter in an input box.

So then you might look up the documentation for the submit event on forms: https://html.spec.whatwg.org/multipage/form-control-infrastr...

And then realize that adding the onclick handler on the submit button handles one use case (clicking the button), but a more general solution would be to add the onclick handlers on the form itself.

Then maybe you start thinking, huh, what happens when someone tabs to a button and presses enter, does the onclick handler work there? And so on and so on...

So the answer for where it's written down, it's in the documentation. But most people these days can't be bothered with things like reading documentation and textbooks and reference manuals, so, uh, I guess you just need to have a little bit of experience combined with an attention to detail?

Re:Show HN: Help Me Decide Please by masonhensley on Friday April 24, 2020 @10:56PM (#22975174)
Not that granular yet, but I’ve been capturing user story/ acceptance criteria level best practices. Currently at ~800 B2B focused modular “specs” that find the middle ground between devs and non technical team members.

My email in profile if you’d like to check it out.

Re:Show HN: Help Me Decide Please by austincheney on Friday April 24, 2020 @10:51PM (#22975152)
No because the default behaviors not defined by a standard. Example: https://forum.vivaldi.net/topic/43170/backspace-shortcut-sho...
Re:Show HN: Help Me Decide Please by franciscop on Saturday April 25, 2020 @12:55AM (#22975693)
Not that I know of. I learned through years of practice and reading hundreds of varied blog posts. If you find a book or resource like that please ping me.
Re:Show HN: Help Me Decide Please by ct520 on Saturday April 25, 2020 @10:29AM (#22978338)
Not that I know of. Just something you learn from experience or your users will tell you quickly during validation.
Re:Show HN: Help Me Decide Please by amtsh on Saturday April 25, 2020 @10:31AM (#22978355)
best way to learn is to build.
Re:Show HN: Help Me Decide Please by tannerljohnson on Friday April 24, 2020 @09:27PM (#22974772)
fixed :) thanks for the feedback!
Re:Show HN: Help Me Decide Please by franciscop on Saturday April 25, 2020 @01:07AM (#22975743)
No problem! You also have a label repeated, which makes the first item to select the second radio-button:

    <input type="radio" id="factor-weight-4" name="score" value="4">
    <label for="factor-weight-3">super important</label>
    <br>
    <input type="radio" id="factor-weight-3" name="score" value="3">
    <label for="factor-weight-3">pretty important</label>
Re:Show HN: Help Me Decide Please by tannerljohnson on Saturday April 25, 2020 @10:13AM (#22978217)
great catch -- fixed now, thank you!
Re:Show HN: Help Me Decide Please by hanniabu on Friday April 24, 2020 @10:00PM (#22974906)
It'd also be nice if after submitting for one and selecting enter that it autofocuses on the input for the next question so you can start typing without clicking on it.
Re:Show HN: Help Me Decide Please by tannerljohnson on Saturday April 25, 2020 @10:13AM (#22978213)
this has been fixed :D thanks!
Re:Show HN: Help Me Decide Please by stanski on Friday April 24, 2020 @09:13PM (#22974697)
Ah, I thought it was broken.
Re:Show HN: Help Me Decide Please by dheera on Friday April 24, 2020 @10:38PM (#22975084)
or better yet, don't even use <form> for things that don't submit a traditional old-style POST/GET to a server. if you're handling all your logic in javascript on the client side, OR doing everything with AJAJ [0], <form> is unnecessary and you can handle things with button.onClick -- you get to program it just like any other GUI.

[0] most people use JSON not XML so i prefer to call it AJAJ not AJAX

Re:Show HN: Help Me Decide Please by Chickenosaurus on Saturday April 25, 2020 @05:34AM (#22976896)
There are some downsides to that approach. The <form> element has semantic meaning which is lost if it's missing. Screen readers for blind people, browser features such as form auto-fill etc. might not work as expected without this semantic information.

Most web applications I have seen opt to use the form element. The default form browser behaviour can be suppressed easily.