Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pressing Enter key submits the form #81

Closed
purepear opened this issue Aug 2, 2016 · 21 comments
Closed

pressing Enter key submits the form #81

purepear opened this issue Aug 2, 2016 · 21 comments
Assignees
Labels

Comments

@purepear
Copy link

purepear commented Aug 2, 2016

When using up/down keys and then enter key to select it submits the form.. how do i stop it propagating the event?

@sagalbot sagalbot added the bug label Aug 2, 2016
@nacr
Copy link

nacr commented Aug 2, 2016

In your form element add @submit.prevent=""

@purepear
Copy link
Author

purepear commented Aug 2, 2016

i'm using vue-formular ... if you know sth better for handling validation easy.. i'm new to Vue and open to suggestions but i don't think @submit.prevent="" will work with vf-form

@nacr
Copy link

nacr commented Aug 3, 2016

my bad did not realize you were using vue-formular

@sagalbot
Copy link
Owner

sagalbot commented Aug 3, 2016

Hi @purepear thanks for bringing this up. I had @keyup.enter.prevent="typeAheadSelect", but what I really need is @keyup.enter.stop="typeAheadSelect" to stop the enter key event from bubbling up. Will fix and release today.

@sagalbot sagalbot self-assigned this Aug 3, 2016
@purepear
Copy link
Author

purepear commented Aug 4, 2016

Hi @sagalbot, @nacr-dev i did some testing and i fixed it by adding <vue-select @keydown.enter.prevent="" ...> component itself

@davodaslanifakor
Copy link

please more descript about problam ...
i hav somting problam
i have a form and use v-select ajax and when select in list by enter my form submiting but i whant submit when click btn submit form

@antidiestro
Copy link

this hasn't been fixed yet? :(

@davodaslanifakor
Copy link

davodaslanifakor commented Jun 17, 2017

@ReneMoraales
hi don't remember i change my plugin vue-multiselect

@deleugpn
Copy link

Having this issue as well.

@enriqg9
Copy link

enriqg9 commented Jul 25, 2017

Same Here. Having this issue as well.

@deleugpn
Copy link

I added @keydown.enter.prevent="" in the form tag which wraps the component that will have the v-select inside.

@enriqg9
Copy link

enriqg9 commented Jul 26, 2017

I had to add it to the parent component, not to the form itself, as v-select in my case is not a direct child of the <form> element.

<form>
  <component> <!-- Added @keydown.enter.prevent on the root element of this component -->
    <v-select>

@DoDSoftware
Copy link

I dont understand why this is closed. This is still an issue. Why would pressing enter in the search field of the v-select cause the form to submit? Seems like very unexpected behaviour.

@sagalbot
Copy link
Owner

sagalbot commented Oct 2, 2017

@gdev219
Copy link

gdev219 commented Jul 19, 2018

Add @keydown.enter.prevent.self to form tag or parent of where event fires.

@ElvysAraujo
Copy link

Hi @gdev219 , thank you, works perfectly!

@AlexGnatko
Copy link

Add @keydown.enter.prevent.self to form tag or parent of where event fires.

Just to clarify, it turns out that it's enough to put "@keydown.enter.prevent.self" with no value to any DOM element which is a child of the form and a parent of the vue-select.

<div @keydown.enter.prevent.self>
<v-select ... />
</div>

@bagaskarala
Copy link

Add @keypress.enter.native.prevent="" to the v-select element.

So enter to submit form still work in native form element (outside v-select element)

@marcobuccio
Copy link

Adding @keypress.enter.native.prevent="" isn't a good solution for me. The @keypress.enter.native.prevent="" prevent the enter key in the multiselect so the user can't chose an option with press enter.

@avnishjayaswal
Copy link

Hello

I got an answer here please take a look

Vue prevent form submit on enter

thanks

@beakid
Copy link

beakid commented Oct 5, 2023

The only thing that worked for me was using the mapKeydown prop https://vue-select.org/guide/keydown.html#mapkeydown

Template:
<v-select :map-keydown="handlers" ... >

Function:
handlers(map: any, vm: any) {
return {
...map,
13: (e: Event) => {
e.preventDefault();
e.stopImmediatePropagation();
return vm.typeAheadSelect();
}
};
}

This should be the accepted answer imo :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests