Skip to content

Commit

Permalink
fix(form): add no value to custom attribute optionset
Browse files Browse the repository at this point in the history
  • Loading branch information
Birkbjo committed Oct 24, 2023
1 parent 9ecd37d commit de74acf
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/pages/dataElements/form/CustomAttributes.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import i18n from '@dhis2/d2-i18n'
import { InputFieldFF, SingleSelectFieldFF, TextAreaFieldFF } from '@dhis2/ui'
import * as React from 'react'
import { Field as FieldRFF } from 'react-final-form'
Expand All @@ -11,16 +12,25 @@ type CustomAttributeProps = {
index: number
}

type DisplayOptions = Array<{
value: string | undefined
label: string
}>

function CustomAttribute({ attribute, index }: CustomAttributeProps) {
const name = `attributeValues[${index}].value`

if (attribute.optionSet?.options) {
const options = attribute.optionSet?.options.map(
let options: DisplayOptions = [
{ value: undefined, label: i18n.t('<No value>') },
]
const mappedOptions = attribute.optionSet.options.map(
({ code, displayName }) => ({
value: code,
label: displayName,
})
)
options = options.concat(mappedOptions)

return (
<StandardFormSection key={attribute.id}>
Expand Down

0 comments on commit de74acf

Please sign in to comment.