Components: md-autocomplete trigger submit on ENTER

Created on 17 Feb 2017  路  10Comments  路  Source: angular/components

md-autocomplete trigger submit form by ENTER click on option:
Plunker template: https://plnkr.co/edit/0a8lqrodE9WVTZEJprlI?p=preview

has pr

Most helpful comment

This is indeed a bug in my opinion. When using enter on autocomplete field, it needs to prevent submitting the form.

All 10 comments

I am not sure I understand what @Knoxvillekm is after, but it likely relates to my question.

Are there plans for something like a "change" Output in md-select, or "selectItem" I am currently using in

https://ng-bootstrap.github.io/#/components/typeahead

@Knoxvillekm as workaround you can use this:
<form action="" method="POST" (keydown.enter)="$event.preventDefault()">

But keep in mind that it will prevent default behavior for all elements. As an example in textarea it won't trigger new line when hit enter. For avoiding it put an exception in a function like so:

 if (event.target.type !== 'textarea') {
      event.preventDefault();
 }

This is indeed a bug in my opinion. When using enter on autocomplete field, it needs to prevent submitting the form.

I agree with @frankspin89 that the enter should not submit the form. I think that it should just select the option like the md-select does.

I think the same thing exist in mdInput so it's probably related

This is definitely a bug. If ENTER does not trigger submit in a textarea, it shouldn't either for autocomplete

@oshri551 mdInput is different beast. It _should_ submit form when hitting Enter from regular INPUT fields. Unlike in TEXTAREA where you need Enter for paragraph.

And unlike in combo/select and here (autocomplete) where hitting Enter should select activated option but by all means should not submit form.

I was about to file an issue and found this one instead. +1

I've created the PR #3727 that fixes this behavior and if the material team think that it's ok we may get that fixed soon

@jefersonestevo Thank you sir. Hoping that your pr is merged soon.

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

RoxKilly picture RoxKilly  路  3Comments

vitaly-t picture vitaly-t  路  3Comments

MurhafSousli picture MurhafSousli  路  3Comments

julianobrasil picture julianobrasil  路  3Comments

Miiekeee picture Miiekeee  路  3Comments