diff options
Diffstat (limited to 'modern')
-rw-r--r-- | modern/src/common/components/SelectField.jsx | 20 |
1 files changed, 8 insertions, 12 deletions
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 = ({ <Autocomplete size="small" options={items} - getOptionLabel={(option) => { - 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) => ( <MenuItem {...props} key={keyGetter(option)} value={keyGetter(option)}>{titleGetter(option)}</MenuItem> )} |