Signup and login forms

Based on EvilMartians' article See https://evilmartians.com/chronicles/html-best-practices-for-login-and-signup-forms

- It allows password managers to distinguish a login form (current-password) from a sign-up form (new-password) - Don’t set autocomplete="off" if you don’t know what are you doing!
Form submission using Enter only works if the fields are inside <form> tags and there is a single submit button
The placeholder attribute was created to show an example of a potential input, not to describe that input. Moreover, placeholder values will be hidden while users are entering the data, and they also often have contrast issues.
- <input type="checkbox"> I agree with the privacy policy + <label> + <input type="checkbox"> I agree with the privacy policy + </label>
When it comes to forms, in general, every user will make use of the keyboard. So, we need to think about how our UIs are accessible from the keyboard.
<input type="email" autocomplete="username" - class="invalid"> + required aria-invalid="true" aria-errormessage="email-error"> <div id="email-error">Enter a valid email address</div> "aria-invalid" and "aria-errormessage" display validation errors for screen-reader users
We don’t want to distract or confuse users with error animations while they’re inputting data into a form, so don’t display a Not valid email error before a user hasn’t finished their input. As a solution, use change instead of keyup for validation once the user has finished their input (by moving to another control or by submitting the form). Of course, we can use still input/keyup, but only to hide errors during input.
User can often accidentally double-click instead of a single-click. So, to prevent showing some server error, it’s better to disable the button upon form submission.
form.addEventListener('submit', async () => { - await fetch(…) + try { + showLoader() + await fetch(…) + } catch (e) { + showError(e) + } finally { + hideLoader() + } })