0
0
Fork 0

feat: refs #8388 if is number check startsWith wip

This commit is contained in:
Jorge Penadés 2025-01-31 16:01:44 +01:00
parent c83854c4c6
commit 66665ba5dd
2 changed files with 9 additions and 5 deletions

View File

@ -213,9 +213,12 @@ function filter(val, options) {
} }
function matchesSearch(val, search) { function matchesSearch(val, search) {
return /^\d+$/.test(search) ? val.startsWith(search) : val.includes(search); return isDigit(search) ? val.startsWith(search) : val.includes(search);
} }
function isDigit(val) {
return /^\d+$/.test(val);
}
async function fetchFilter(val) { async function fetchFilter(val) {
if (!$props.url) return; if (!$props.url) return;
@ -284,7 +287,9 @@ function nullishToTrue(value) {
return value ?? true; return value ?? true;
} }
const getVal = (val) => ($props.useLike ? { like: `%${val}%` } : val); function getVal(val) {
return $props.useLike ? { like: isDigit(val) ? `${val}%` : `%${val}%` } : val;
}
async function onScroll({ to, direction, from, index }) { async function onScroll({ to, direction, from, index }) {
const lastIndex = myOptions.value.length - 1; const lastIndex = myOptions.value.length - 1;

View File

@ -1,9 +1,7 @@
<script setup> <script setup>
import { computed } from 'vue';
import VnSelect from 'components/common/VnSelect.vue'; import VnSelect from 'components/common/VnSelect.vue';
const model = defineModel({ type: [String, Number, Object] }); const model = defineModel({ type: [String, Number, Object] });
const url = 'Suppliers';
</script> </script>
<template> <template>
@ -11,10 +9,11 @@ const url = 'Suppliers';
:label="$t('globals.supplier')" :label="$t('globals.supplier')"
v-bind="$attrs" v-bind="$attrs"
v-model="model" v-model="model"
:url="url" url="Suppliers"
option-value="id" option-value="id"
option-label="nickname" option-label="nickname"
:fields="['id', 'name', 'nickname', 'nif']" :fields="['id', 'name', 'nickname', 'nif']"
:filter-options="['id', 'name', 'nickname', 'nif']"
sort-by="name ASC" sort-by="name ASC"
> >
<template #option="scope"> <template #option="scope">