fix: value option no set

This commit is contained in:
Thanaphon Frappet 2025-08-14 11:07:01 +07:00
parent 968aa04aa9
commit 42e545dd66

View file

@ -35,7 +35,13 @@ export const createSelect = <T extends Record<string, any>>(
let previousSearch = '';
watch(value, (v) => {
if (!v || (cache && cache.find((opt) => opt[valueField] === v))) return;
if (!v) return;
if (cache && cache.find((opt) => opt[valueField] === v)) {
valueOption.value = cache.find((opt) => opt[valueField] === v);
return;
}
getSelectedOption();
});
@ -63,7 +69,15 @@ export const createSelect = <T extends Record<string, any>>(
const currentValue = value.value;
if (!currentValue) return;
if (selectOptions.value.find((v) => v[valueField] === currentValue)) return;
const option = selectOptions.value.find(
(v) => v[valueField] === currentValue,
);
if (option) {
valueOption.value = option;
return;
}
if (valueOption.value && valueOption.value[valueField] === currentValue) {
return selectOptions.value.unshift(valueOption.value);
}