From 2bd044ecf9fa456e168057acc513bd3b4582d0c6 Mon Sep 17 00:00:00 2001 From: Matjaž Črnko Date: Mon, 22 Jan 2024 15:22:33 +0100 Subject: fix: SelectField better label code --- modern/src/common/components/SelectField.jsx | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'modern') diff --git a/modern/src/common/components/SelectField.jsx b/modern/src/common/components/SelectField.jsx index dc31a156..bc0571d5 100644 --- a/modern/src/common/components/SelectField.jsx +++ b/modern/src/common/components/SelectField.jsx @@ -20,6 +20,13 @@ const SelectField = ({ }) => { const [items, setItems] = useState(data); + const getOptionLabel = (option) => { + if (typeof option !== 'object') { + option = items.find(obj => keyField ? obj[keyField] === option : obj === option); + } + return option ? titleGetter(option) : ''; + } + useEffectAsync(async () => { if (endpoint) { const response = await fetch(endpoint); @@ -53,18 +60,7 @@ const SelectField = ({ { - if (typeof option != 'object') { - if (keyField) { - option = items.find(obj => obj[keyField] === option) - } else { - option = items.find(obj => obj === option) - } - } - const title = option ? titleGetter(option) : '' - return title ? title : '' - } - } + getOptionLabel={getOptionLabel} renderOption={(props, option) => ( {titleGetter(option)} )} -- cgit v1.2.3