sindresorhus/refined-github

Avoid accidental form submissions #4248

fregante posted onGitHub

Replaces https://github.com/sindresorhus/refined-github/issues/3911

Pressing the Enter key while you're in a regular input field will submit the form. This means that if you're typing a message and fat-finger the Enter key, you might have made an irreversible change.

This is not so much of an issue when creating an issue since it can be changed later, but it's a problem when merging PRs and saving file changes on the file edit page. Both of them create commits, possibly on the main branch.

Instead of adding annoying prompts, we have 2 options:

  • disable the enter key in issue/PR/commit title fields
  • re-map the enter key to act as a <kbd>tab</kbd> in those fields, so it will merely move the cursor to the textarea

I think the latter is preferable because the former would just feel like the enter key is suddenly broken.

Either way, the form will still be submittable via ctrl+enter as it already is.


The solution probably looks like:

delegate(document, 'the right selector', 'keypress', e => {
    if (e is enter key)
        select('textarea', e.delegateTarget.form).focus();
})

@fregante I made PR #4252 following your solution (adding e.preventDefault()) and renamed the feature as avoid-accidental-submissions .

posted by darkred almost 4 years ago

Fund this Issue

$0.00
Funded

Pull requests