Skip to content

Commit

Permalink
fix(custom attributes optionsets): add no-value-option only when not …
Browse files Browse the repository at this point in the history
…required
  • Loading branch information
Mohammer5 committed Oct 30, 2023
1 parent 8ab3090 commit c10ec33
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/pages/dataElements/form/CustomAttributes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,25 @@ type CustomAttributeProps = {

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

if (attribute.optionSet?.options) {
const attributeOptions = attribute.optionSet?.options.map(
const options = attribute.optionSet?.options.map(
({ code, displayName }) => ({
value: code,
label: displayName,
})
)

const options = [
{ value: '', label: i18n.t('<No value>') },
...(attributeOptions || []),
]
if (required) {
options.unshift({ value: '', label: i18n.t('<No value>') })
}

return (
<StandardFormSection key={attribute.id}>
<FieldRFF
component={SingleSelectFieldFF}
required={attribute.mandatory}
required={required}
inputWidth={inputWidth}
label={attribute.displayFormName}
name={name}
Expand All @@ -47,7 +47,7 @@ function CustomAttribute({ attribute, index }: CustomAttributeProps) {
<StandardFormSection key={attribute.id}>
<FieldRFF
component={InputFieldFF}
required={attribute.mandatory}
required={required}
inputWidth={inputWidth}
label={attribute.displayFormName}
name={name}
Expand All @@ -61,7 +61,7 @@ function CustomAttribute({ attribute, index }: CustomAttributeProps) {
<StandardFormSection key={attribute.id}>
<FieldRFF
component={TextAreaFieldFF}
required={attribute.mandatory}
required={required}
inputWidth={inputWidth}
label={attribute.displayFormName}
name={name}
Expand Down

0 comments on commit c10ec33

Please sign in to comment.