Skip to content

"Enter" handling when dropdown is not visible #155

@SurpriseAlberto

Description

@SurpriseAlberto

IMHO, when dropdown of autocomplete is not shown, the behaviour of the field should ignore the preventEnter setting. In other words, if the field with autocomplete is part of a form and the dropdown is not shown, by pressing enter the browser should submit the form.
I would then recommend the following change in main.ts from line 225

case 13: // ENTER
          var isDropDownVisible = this._dd.isShown();
          if (this._dd.isItemFocused) {
            this._dd.selectFocusItem();
          } else if (!this._selectedItem) {
            if (this._$el.val() !== '') {
              this._$el.trigger('autocomplete.freevalue', this._$el.val());
            }
          }
          this._dd.hide();
          if (isDropDownVisible && this._settings.preventEnter) {
            // console.log('preventDefault');
            evt.preventDefault();
          }
          break;

Alternatively, you may change the setting preventEnter to support multiple values:

  • always
  • only when dropdown is visible
  • never

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