Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ [open-formulieren/open-forms#5073] Option to transform Selectboxes data #209

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {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 @@
{/* Registration tab */}
<TabPanel>
<Registration.RegistrationAttributeSelect />
<TransformData />
</TabPanel>

{/* Translations */}
Expand Down Expand Up @@ -149,6 +151,7 @@
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;
Loading