kraaden / autocomplete

Blazing fast and lightweight autocomplete widget without dependencies. Only 1KB gzipped. Demo:

Home Page:https://smartscheduling.com/en/documentation/autocomplete

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Prevent submit on enter only when the autocomplete is displayed

ofrias opened this issue · comments

The preventSubmit setting should only be applied when the autocomplete list is visible. If the enter is pressed while the focus is on the input field the form should be submited.

Sample code:

              var isOpen = containerDisplayed();
              if (selected) {
                  settings.onSelect(selected, input);
                  clear();
              }
              if (preventSubmit && isOpen) {
                  ev.preventDefault();
              }

commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

I think this is still active, my PR #89 should fix this.

Unfortunately this issue is not fixed in the current version. You can reproduce it by including the input in a form and pressing enter while the input is focused (without the autocomplete list visible). The browser won't post the form (because of the ev.preventDefault() call) but it should. The sample code is still applicable to the current version and fixes the issue.

@ofrias Have you tried if #89 fixes it for you?

Oops, I didn't noticed the PR was not merged in trunk yet. I have just tried and yes, it fixes it too.

@ofrias @Taitava

You can now use the following option to prevent form submissions only when an item is selected in autocomplete:

autocomplete({
    ...,
    preventSubmit: PreventSubmit.OnSelect
});

You also need to install the following version:

npm install --save-dev autocompleter@9.0.0-alpha.1

I will close the issue, but if something is not working as expected - let me know.

@kraaden so, is PR #89 redundant now? 🙂

@Taitava Yes, thanks! I closed the PR