Skip to content

Commit

Permalink
bugfix: enum options coming from the layout field were not rendering …
Browse files Browse the repository at this point in the history
…due to being a string array instead of a label/value pair
  • Loading branch information
Jon Carlson committed Mar 7, 2024
1 parent f383f18 commit c515b32
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ function optionHasValue(option) {
return option != ''
}

function getEnumOptionsAsLabelValue(
enumOptions: string[] | { label: string; value: string }[]
) {
return (
enumOptions
?.filter(optionHasValue)
.map(option =>
typeof option === 'string' ? { label: option, value: option } : option
) ?? []
)
}

function MultiSelectWidget(props: WidgetProps) {
const {
id,
Expand All @@ -35,7 +47,7 @@ function MultiSelectWidget(props: WidgetProps) {

let tagifyOptions = {
mode: !props.multiple ? 'select' : null,
whitelist: options.enumOptions?.filter(optionHasValue) ?? [],
whitelist: getEnumOptionsAsLabelValue(options.enumOptions),
enforceWhitelist:
'enforceEnumOptions' in options ? options.enforceEnumOptions : true,
keepInvalidTags:
Expand Down Expand Up @@ -66,7 +78,7 @@ function MultiSelectWidget(props: WidgetProps) {
useEffect(() => {
if (!tagify) return

tagify.settings.whitelist = options.enumOptions?.filter(optionHasValue) ?? []
tagify.settings.whitelist = getEnumOptionsAsLabelValue(options.enumOptions)
}, [tagify, options.enum, options.enumOptions])

let filteredValue = value && typeof value === 'string' ? [value] : value
Expand Down

0 comments on commit c515b32

Please sign in to comment.