Skip to content

Dont submit form when pressing Enter #146

@brentgreeff

Description

@brentgreeff

When the input used for searching is part of a form with other fields,
its very easy to use the Enter to select an option, but then also to press Enter and submit the whole form,
which I did accidentally many times.

data-autocomplete-submit-on-enter-value="false" - does not do what I would expect.

input[type="text" data-autocomplete-target="input" data-action="keydown.enter->autocomplete#bad"]
class CustomAutocomplete extends Autocomplete {

  bad(e) {
    e.preventDefault()
  }
}
application.register('autocomplete', CustomAutocomplete)

This worked for me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions