Skip to content

Commit

Permalink
Use select options value and label
Browse files Browse the repository at this point in the history
  • Loading branch information
rogargon committed Dec 18, 2023
1 parent c92d901 commit 2eef7fb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
20 changes: 7 additions & 13 deletions src/components/@shared/FormInput/InputElement/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ const InputElement = forwardRef(
const sortedOptions =
!sortOptions && sortOptions === false
? options
: (options as string[]).sort((a: string, b: string) =>
a.localeCompare(b)
: (options as string[]).sort((a: any, b: any) =>
a.label.localeCompare(b.label)
)
return (
<select
Expand All @@ -96,17 +96,11 @@ const InputElement = forwardRef(
>
{field !== undefined && field.value === '' && <option value="" />}
{sortedOptions &&
(sortedOptions as string[]).map(
(option: string, index: number) => (
<option key={index} value={option}>
<Option
option={option}
prefix={prefixes?.[index]}
postfix={postfixes?.[index]}
/>
</option>
)
)}
(sortedOptions as any[]).map((option, index: number) => (
<option key={index} value={option.value}>
{option.label}
</option>
))}
</select>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ export default function FormConsumerParameters({
parameter.type === 'boolean'
? ['true', 'false']
: parameter.type === 'select'
? JSON.parse(parameter.options)?.map((option) => Object.keys(option)[0])
? JSON.parse(parameter.options)?.map((option) => {
return {
value: Object.keys(option)[0],
label: Object.values(option)[0]
}
})
: []

// add empty option, if parameter is optional
Expand Down

0 comments on commit 2eef7fb

Please sign in to comment.