fix: refs #8647 add filter function prop to VnSelect component and refactor bank entity filter logic
This commit is contained in:
parent
561db9f7c8
commit
55d51ddf22
|
@ -54,6 +54,10 @@ const $props = defineProps({
|
|||
type: [Array],
|
||||
default: () => [],
|
||||
},
|
||||
filterFn: {
|
||||
type: Function,
|
||||
default: null,
|
||||
},
|
||||
exprBuilder: {
|
||||
type: Function,
|
||||
default: null,
|
||||
|
@ -62,10 +66,6 @@ const $props = defineProps({
|
|||
type: Boolean,
|
||||
default: true,
|
||||
},
|
||||
defaultFilter: {
|
||||
type: Boolean,
|
||||
default: true,
|
||||
},
|
||||
fields: {
|
||||
type: Array,
|
||||
default: null,
|
||||
|
@ -247,15 +247,11 @@ async function fetchFilter(val) {
|
|||
}
|
||||
|
||||
async function filterHandler(val, update) {
|
||||
if (!val && lastVal.value === val) {
|
||||
lastVal.value = val;
|
||||
return update();
|
||||
}
|
||||
lastVal.value = val;
|
||||
let newOptions;
|
||||
|
||||
if (!$props.defaultFilter) return update();
|
||||
if (
|
||||
if ($props.filterFn) update($props.filterFn(val));
|
||||
else if (!val && lastVal.value === val) update();
|
||||
else if (
|
||||
$props.url &&
|
||||
($props.limit || (!$props.limit && Object.keys(myOptions.value).length === 0))
|
||||
) {
|
||||
|
@ -275,6 +271,8 @@ async function filterHandler(val, update) {
|
|||
}
|
||||
},
|
||||
);
|
||||
|
||||
lastVal.value = val;
|
||||
}
|
||||
|
||||
function nullishToTrue(value) {
|
||||
|
|
|
@ -65,15 +65,13 @@ function findBankFk(value, row) {
|
|||
if (bankEntityFk) row.bankEntityFk = bankEntityFk.id;
|
||||
}
|
||||
|
||||
function bankEntityFilter(val, update) {
|
||||
update(() => {
|
||||
const needle = val.toLowerCase();
|
||||
filteredBankEntitiesOptions.value = bankEntitiesOptions.value.filter(
|
||||
(bank) =>
|
||||
bank.bic.toLowerCase().startsWith(needle) ||
|
||||
bank.name.toLowerCase().includes(needle),
|
||||
);
|
||||
});
|
||||
function bankEntityFilter(val) {
|
||||
const needle = val.toLowerCase();
|
||||
filteredBankEntitiesOptions.value = bankEntitiesOptions.value.filter(
|
||||
(bank) =>
|
||||
bank.bic.toLowerCase().startsWith(needle) ||
|
||||
bank.name.toLowerCase().includes(needle),
|
||||
);
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
|
@ -82,7 +80,8 @@ function bankEntityFilter(val, update) {
|
|||
url="BankEntities"
|
||||
@on-fetch="
|
||||
(data) => {
|
||||
(bankEntitiesOptions = data), (filteredBankEntitiesOptions = data);
|
||||
bankEntitiesOptions = data;
|
||||
filteredBankEntitiesOptions = data;
|
||||
}
|
||||
"
|
||||
auto-load
|
||||
|
@ -135,10 +134,8 @@ function bankEntityFilter(val, update) {
|
|||
:label="t('worker.create.bankEntity')"
|
||||
v-model="row.bankEntityFk"
|
||||
:options="filteredBankEntitiesOptions"
|
||||
:default-filter="false"
|
||||
@filter="(val, update) => bankEntityFilter(val, update)"
|
||||
:filter-fn="bankEntityFilter"
|
||||
option-label="bic"
|
||||
option-value="id"
|
||||
hide-selected
|
||||
:required="true"
|
||||
:roles-allowed-to-create="['financial']"
|
||||
|
|
|
@ -145,9 +145,7 @@ async function remove(row) {
|
|||
emit-value
|
||||
map-options
|
||||
:label="t('globals.type')"
|
||||
:options="filteredWagonTypes"
|
||||
:rules="[(val) => !!val || t('wagon.warnings.typeNotEmpty')]"
|
||||
@filter="filterType"
|
||||
>
|
||||
<template v-if="data.typeFk" #append>
|
||||
<QIcon
|
||||
|
@ -172,4 +170,4 @@ async function remove(row) {
|
|||
<i18n>
|
||||
es:
|
||||
Create new wagon: Crear nuevo vagón
|
||||
</i18n>
|
||||
</i18n>
|
||||
|
|
Loading…
Reference in New Issue