Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,13 @@ pnpm add vue-search-select
| | customAttr | Function | () => '' | Add custom html attribute |
| | name | String | | input form name attribute |
| | id | String | | id attribute |
| | debounce | Number | | wait time between inputs before triggering the "searchchange" event |
| | searchchange | Event | | event triggered on search change |
| | blur | Event | | event triggered on input blur |
| ModelListSelect | list | Array | | option list |
| | optionValue | String | | value key |
| | optionText | String | | text key |
| | debounce | Number | | wait time between inputs before triggering the "searchchange" event |
| | customText | Function | | custom text function |
| | optionDisabled | String | false | disabled key |
| | isError | Boolean | false | error style |
Expand All @@ -99,6 +101,7 @@ pnpm add vue-search-select
| | hideSelectedOptions | Boolean | false | Hide Option list that item selected |
| | name | String | | input form name attribute |
| | id | String | | id attribute |
| | debounce | Number | | wait time between inputs before triggering the "searchchange" event |
| | searchchange | Event | | event triggered on search change |
| | blur | Event | | event triggered on input blur |
| | select | Event | | event triggered when item selected |
Expand All @@ -114,6 +117,7 @@ pnpm add vue-search-select
| | filterPredicate | String | new RegExp(inputText, 'i') | |
| | name | String | | input form name attribute |
| | id | String | | id attribute |
| | debounce | Number | | wait time between inputs before triggering the "searchchange" event |
| | searchchange | Event | | event triggered on search change |
| | blur | Event | | event triggered on input blur |
| | select | Event | | event triggered when item selected |
Expand Down
45 changes: 45 additions & 0 deletions docs/src/views/ModelAjax.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,43 @@
</div>
</div>
</div>
<div class="ui vertical segment">
<div class="flexbox">
<div class="flex-content">
<h3>Dynamic Search with ajax and 500ms debounce (country name)</h3>
<div>
<model-list-select
:list="countries"
option-value="code"
option-text="name"
v-model="selectedCountryDebounce"
debounce="500"
placeholder="select item"
@searchchange="searchCountry"
>
</model-list-select>
</div>
</div>
<div class="flex-result">
<h4>input text(searchText)</h4>
<p>{{ searchText }}</p>
<table class="ui celled table">
<thead>
<tr>
<th>code</th>
<th>name</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{ selectedCountryDebounce.code }}</td>
<td>{{ selectedCountryDebounce.name }}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="ui vertical segment">
<div class="flexbox">
<div class="flex-content">
Expand Down Expand Up @@ -89,7 +126,9 @@ export default {
return {
countries: [],
selectedCountry: {},
selectedCountryDebounce: {},
searchText: "",
searchTextDebounce: "",
animations: [],
selectedAnimation: {},
searchText2: "",
Expand All @@ -105,6 +144,12 @@ export default {
this.countries = response
})
},
searchCountryDebounce(searchText) {
this.searchTextDebounce = searchText
ajaxFindCountry(searchText).then(response => {
this.countries = response
})
},
printSearchText(searchText) {
this.searchText2 = searchText
},
Expand Down
1 change: 1 addition & 0 deletions libs/components/ModelListSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default {
id: this.id,
name: this.name,
options: this.options,
debounce: this.debounce,
modelValue: this.innerValue,
isError: this.isError,
isDisabled: this.isDisabled,
Expand Down
8 changes: 7 additions & 1 deletion libs/components/ModelSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export default {
searchText: "",
mousedownState: false, // mousedown on option menu
pointer: -1,
timeout: null,
}
},
watch: {
Expand All @@ -92,7 +93,12 @@ export default {
this.pointerAdjust()
},
searchText() {
this.$emit("searchchange", this.searchText)
if(this.debounce > 0){
clearTimeout(this.timeout);
this.timeout = setTimeout(() => {this.$emit("searchchange", this.searchText)}, this.debounce);
} else {
this.$emit("searchchange", this.searchText)
}
},
},
computed: {
Expand Down
1 change: 1 addition & 0 deletions libs/components/MultiListSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default {
id: this.id,
name: this.name,
options: this.options,
debounce: this.debounce,
selectedOptions: this.items,
isError: this.isError,
isDisabled: this.isDisabled,
Expand Down
8 changes: 7 additions & 1 deletion libs/components/MultiSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export default {
searchText: "",
mousedownState: false, // mousedown on option menu
pointer: -1,
timeout: null,
}
},
watch: {
Expand All @@ -109,7 +110,12 @@ export default {
this.pointerAdjust()
},
searchText() {
this.$emit("searchchange", this.searchText)
if(this.debounce > 0){
clearTimeout(this.timeout);
this.timeout = setTimeout(() => {this.$emit("searchchange", this.searchText)}, this.debounce);
} else {
this.$emit("searchchange", this.searchText)
}
},
},
computed: {
Expand Down
4 changes: 4 additions & 0 deletions libs/components/mixins/commonMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export default {
type: String,
default: "",
},
debounce: {
type: Number,
default: 0
},
filterPredicate: {
type: Function,
default: (text, inputText) => {
Expand Down