Skip to content

Commit

Permalink
fix(input): do not submit the form if there was a menu choice (if the…
Browse files Browse the repository at this point in the history
… component is inside the form)

re #196
  • Loading branch information
iliyaZelenko committed Sep 13, 2019
1 parent 6fd9957 commit 50bc64d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
17 changes: 17 additions & 0 deletions gh-pages-src/pages/dev/Example5.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@
<b>Selected:</b> {{ selected || 'not chosen' }}.
<br><br>

<form @submit="onSubmit">
<cool-select
v-model="selected"
:items="items"
placeholder="Select name"
@keydown.enter.native="onEnter"
/>
</form>

<br>

<cool-select
v-model="selected"
:items="items"
Expand Down Expand Up @@ -99,6 +110,12 @@ export default {
}
},
methods: {
onSubmit () {
alert('Submit!')
},
onEnter () {
alert('onEnter!')
},
validate () {
this.errorMessage = this.selected ? null : 'This is required field!'
}
Expand Down
4 changes: 3 additions & 1 deletion src/eventsListeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ export default {
})
}
},
onEnter () {
onEnter (e) {
if (this.hasMenu) {
e.preventDefault()

let needToResetSearch = false
// если не выбрано через стрелки, то выбирать первый элемент
if (!this.arrowsIndex && !this.disableFirstItemSelectOnEnter) {
Expand Down

0 comments on commit 50bc64d

Please sign in to comment.