Skip to content

Commit

Permalink
✨ [open-formulieren/open-forms#5073] Option to transform Selectboxes …
Browse files Browse the repository at this point in the history
…data

to a list of values instead of an object that maps values to true/false
  • Loading branch information
stevenbal committed Feb 4, 2025
1 parent 78a667e commit 4ad054c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/registry/selectboxes/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {useErrorChecker} from '@/utils/errors';

import {EditFormDefinition} from '../types';
import {checkIsManualOptions} from './helpers';
import TransformData from './transform-data';

/**
* Form to configure a Formio 'selectboxes' type component.
Expand Down Expand Up @@ -116,6 +117,7 @@ const EditForm: EditFormDefinition<SelectboxesComponentSchema> = () => {
{/* Registration tab */}
<TabPanel>
<Registration.RegistrationAttributeSelect />
<TransformData />
</TabPanel>

{/* Translations */}
Expand Down Expand Up @@ -149,6 +151,7 @@ EditForm.defaultValues = {
openForms: {
dataSrc: 'manual',
translations: {},
transformData: false,

Check failure on line 154 in src/registry/selectboxes/edit.tsx

View workflow job for this annotation

GitHub Actions / Create 'production' build

Type '{ dataSrc: "manual"; translations: {}; transformData: false; }' is not assignable to type '({ translations: ComponentTranslations<TranslatableKeys>; } & ManualValues) | ({ translations: ComponentTranslations<TranslatableKeys>; } & VariableValues)'.
},
values: [{value: '', label: ''}],
// TODO: check that the initial values are set based on component.values
Expand Down
32 changes: 32 additions & 0 deletions src/registry/selectboxes/transform-data.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {FormattedMessage, useIntl} from 'react-intl';

import {Checkbox} from '@/components/formio';

const TransformData = () => {
const intl = useIntl();
const tooltip = intl.formatMessage(
{
description: "Tooltip for selectboxes 'Transform data' builder field",
defaultMessage: `Transform the submitted data to a list with the selected choices, instead of an
object that maps choices to <code>true</code> or <code>false</code> (dependent on whether they are selected).`,
},
{
code: chunks => <code>{chunks}</code>,
}
) as string; // library doesn't narrow the type when using template fns :(

return (
<Checkbox
name="openForms.transformData"
label={
<FormattedMessage
description="Label for selectboxes 'Transform data' builder field"
defaultMessage="Transform submitted data to list of values"
/>
}
tooltip={tooltip}
/>
);
};

export default TransformData;

0 comments on commit 4ad054c

Please sign in to comment.