Skip to content

Commit

Permalink
fix: input event on component's created hook. The items prop is not r…
Browse files Browse the repository at this point in the history
…equired when simple-input prop
  • Loading branch information
iliyaZelenko committed Nov 12, 2019
1 parent d2ccb64 commit b2c17b4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
16 changes: 9 additions & 7 deletions gh-pages-src/pages/dev/Example5.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@
<b>Selected:</b> {{ selected || 'not chosen' }}.
<br><br>

{{ selectTextOnFocus }}

<cool-select
ref="select"
v-model="selected"
:items="items"
v-model="selected2"
:items="items2"
:error-message="errorMessage"
:disabled="disabled"
:readonly="readonly"
Expand All @@ -26,8 +24,8 @@
<br>

<cool-select
v-model="selected"
:items="items"
v-model="selected2"
:items="items2"
:error-message="errorMessage"
:successful="!!(!errorMessage && selected)"
:disabled="disabled"
Expand Down Expand Up @@ -121,6 +119,8 @@
<script>
import { CoolSelect } from '../../main'
const items2 = [{ 'first_name': 'one' }, { 'first_name': 'two' }, { 'first_name': 'three' }, { 'first_name': 'four' }, { 'first_name': 'five' }]
export default {
components: { CoolSelect },
data: () => ({
Expand All @@ -129,8 +129,10 @@ export default {
readonly: false,
disableSearch: false,
selectTextOnFocus: false,
selected: null,
items: '[{"first_name":"one"}, {"first_name":"two"}, {"first_name":"three"}, {"first_name":"four"}, {"first_name":"five"}]',
items2,
selected: null,
selected2: items2[0],
errorMessage: null
}),
watch: {
Expand Down
10 changes: 9 additions & 1 deletion src/component.vue
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,9 @@ export default {
resize: this.menuCalculatePos
},
menuCurrentPosition: this.menuDefaultPosition,
lastMenuDynamicStyles: null
lastMenuDynamicStyles: null,
// чтобы не вызывался input из-за selectedItem (в created вызывается setSelectedItemByValue)
ignoreFirstInputEvent: true
}
},
computed,
Expand All @@ -248,6 +250,12 @@ export default {
this.setSelectedItemByValue()
},
selectedItem () {
if (this.ignoreFirstInputEvent) {
this.ignoreFirstInputEvent = false
return
}
this.selectedItemByArrows = null
this.$emit('input', this.currentItemValue)
Expand Down
2 changes: 1 addition & 1 deletion src/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default {
},
items: {
type: [Array, String],
required: true,
required: false,
note: 'array of suggestions (data fetched from backend, etc).'
},
itemText: {
Expand Down

0 comments on commit b2c17b4

Please sign in to comment.