fix: refactor TypeAsyncDropdown value handling for improved clarity and consistency

This commit is contained in:
faisolavolut 2025-03-05 13:55:04 +07:00
parent 57b87bf707
commit 5f69723075
1 changed files with 55 additions and 48 deletions

View File

@ -191,6 +191,7 @@ export const TypeAsyncDropdown: React.FC<any> = ({
const clearable =
mode === "dropdown" && required ? false : mode === "multi" ? true : true;
let value = fm.data[name];
if (value) {
if (mode === "multi") {
if (Array.isArray(value) && value?.length) {
value = value.map((e) => {
@ -204,18 +205,20 @@ export const TypeAsyncDropdown: React.FC<any> = ({
value = [];
}
} else if (typeof value === "object") {
value = {
value = value
? {
value: getValue(value),
label: getLabel(value),
};
}
: null;
} else if (
!target &&
typeof value !== "object" &&
typeof value === "string" &&
value
) {
value =
onValue === onLabel
value = value
? onValue === onLabel
? {
value: value,
label: value,
@ -223,7 +226,8 @@ export const TypeAsyncDropdown: React.FC<any> = ({
: {
value: value,
label: getLabel(value),
};
}
: null;
} else if (typeof value === "string") {
value =
onValue === onLabel
@ -244,11 +248,14 @@ export const TypeAsyncDropdown: React.FC<any> = ({
};
});
} else if (typeof value === "object" && value) {
value = {
value = value
? {
...value,
value: getValue(value),
label: getLabel(value),
};
}
: value;
}
}
const CustomMenu = (props: any) => {
return (