Skip to content

Commit 4d5f250

Browse files
committedJun 19, 2024·
fix(InputMenu/SelectMenu): invalid label with value-attribute and async search
Resolves #1780
1 parent 6b6b03d commit 4d5f250

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed
 

‎src/runtime/components/forms/InputMenu.vue

+12-8
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ export default defineComponent({
309309
}
310310
311311
if (props.valueAttribute) {
312-
const option = props.options.find(option => option[props.valueAttribute] === props.modelValue)
312+
const option = options.value.find(option => option[props.valueAttribute] === props.modelValue)
313313
return option ? option[props.optionAttribute] : null
314314
} else {
315315
return ['string', 'number'].includes(typeof props.modelValue) ? props.modelValue : props.modelValue[props.optionAttribute]
@@ -391,16 +391,22 @@ export default defineComponent({
391391
392392
const debouncedSearch = props.search && typeof props.search === 'function' ? useDebounceFn(props.search, props.debounce) : undefined
393393
394-
const filteredOptions = computedAsync(async () => {
395-
if (debouncedSearch) {
394+
const options = computedAsync(async () => {
395+
if (props.search && debouncedSearch) {
396396
return await debouncedSearch(query.value)
397397
}
398398
399-
if (query.value === '') {
400-
return props.options
399+
return props.options || []
400+
}, [], {
401+
lazy: props.searchLazy
402+
})
403+
404+
const filteredOptions = computed(() => {
405+
if (!query.value) {
406+
return options.value
401407
}
402408
403-
return (props.options as any[]).filter((option: any) => {
409+
return options.value.filter((option: any) => {
404410
return (props.searchAttributes?.length ? props.searchAttributes : [props.optionAttribute]).some((searchAttribute: any) => {
405411
if (['string', 'number'].includes(typeof option)) {
406412
return String(option).search(new RegExp(query.value, 'i')) !== -1
@@ -411,8 +417,6 @@ export default defineComponent({
411417
return child !== null && child !== undefined && String(child).search(new RegExp(query.value, 'i')) !== -1
412418
})
413419
})
414-
}, [], {
415-
lazy: props.searchLazy
416420
})
417421
418422
watch(container, (value) => {

‎src/runtime/components/forms/SelectMenu.vue

+12-8
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ export default defineComponent({
368368
}
369369
} else if (props.modelValue !== undefined && props.modelValue !== null) {
370370
if (props.valueAttribute) {
371-
const option = props.options.find(option => option[props.valueAttribute] === props.modelValue)
371+
const option = options.value.find(option => option[props.valueAttribute] === props.modelValue)
372372
return option ? option[props.optionAttribute] : null
373373
} else {
374374
return ['string', 'number'].includes(typeof props.modelValue) ? props.modelValue : props.modelValue[props.optionAttribute]
@@ -452,18 +452,24 @@ export default defineComponent({
452452
)
453453
})
454454
455-
const debouncedSearch = typeof props.searchable === 'function' ? useDebounceFn(props.searchable, props.debounce) : undefined
455+
const debouncedSearch = props.searchable && typeof props.searchable === 'function' ? useDebounceFn(props.searchable, props.debounce) : undefined
456456
457-
const filteredOptions = computedAsync(async () => {
457+
const options = computedAsync(async () => {
458458
if (props.searchable && debouncedSearch) {
459459
return await debouncedSearch(query.value)
460460
}
461461
462-
if (query.value === '') {
463-
return props.options
462+
return props.options || []
463+
}, [], {
464+
lazy: props.searchableLazy
465+
})
466+
467+
const filteredOptions = computed(() => {
468+
if (!query.value) {
469+
return options.value
464470
}
465471
466-
return (props.options as any[]).filter((option: any) => {
472+
return options.value.filter((option: any) => {
467473
return (props.searchAttributes?.length ? props.searchAttributes : [props.optionAttribute]).some((searchAttribute: any) => {
468474
if (['string', 'number'].includes(typeof option)) {
469475
return String(option).search(new RegExp(query.value, 'i')) !== -1
@@ -474,8 +480,6 @@ export default defineComponent({
474480
return child !== null && child !== undefined && String(child).search(new RegExp(query.value, 'i')) !== -1
475481
})
476482
})
477-
}, [], {
478-
lazy: props.searchableLazy
479483
})
480484
481485
const createOption = computed(() => {

0 commit comments

Comments
 (0)
Please sign in to comment.