Skip to content

Commit

Permalink
🐛 [open-formulieren/open-forms#4772] Set select dataType to string
Browse files Browse the repository at this point in the history
because Select components did not have a dataType set, formio tries to cast it to other types if possible, which causes issues when submitting the data to the backend. For that reason we set the value to string to avoid this unwanted normalization
  • Loading branch information
stevenbal committed Nov 11, 2024
1 parent 4bd994b commit a638bf3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/formio/components/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ interface BaseSelectSchema {
// dynamic values into data.values already.
// So our openForms.dataSrc == itemsExpression results in dataSrc == values.
dataSrc: 'values';
// Fix for https://github.com/open-formulieren/open-forms/issues/4772
// ensure the datatype is set to string to avoid formio casting it to other
// types (such as integer)
dataType: 'string';
}

/**
Expand Down
7 changes: 7 additions & 0 deletions test-d/formio/components/select.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ expectAssignable<SelectComponentSchema>({
id: 'yejak',
type: 'select',
dataSrc: 'values',
dataType: 'string',
key: 'someSelect',
label: 'Some select',
openForms: {
Expand All @@ -28,6 +29,7 @@ expectAssignable<SelectComponentSchema>({
id: 'yejak',
type: 'select',
dataSrc: 'values',
dataType: 'string',
key: 'someSelect',
label: 'Some select',
openForms: {
Expand All @@ -42,6 +44,7 @@ expectAssignable<SelectComponentSchema>({
id: 'yejak',
type: 'select',
dataSrc: 'values',
dataType: 'string',
key: 'someSelect',
label: 'Some select',
multiple: false,
Expand All @@ -58,6 +61,7 @@ expectAssignable<SelectComponentSchema>({
id: 'yejak',
type: 'select',
dataSrc: 'values',
dataType: 'string',
key: 'someSelect',
label: 'Some select',
multiple: true,
Expand All @@ -74,6 +78,7 @@ expectAssignable<SelectComponentSchema>({
id: 'yejak',
type: 'select',
dataSrc: 'values',
dataType: 'string',
key: 'someSelect',
label: 'Some select',
multiple: true,
Expand All @@ -90,6 +95,7 @@ expectAssignable<SelectComponentSchema>({
id: 'yejak',
type: 'select',
dataSrc: 'values',
dataType: 'string',
key: 'someSelect',
label: 'Some select',
defaultValue: 'dummy',
Expand Down Expand Up @@ -122,6 +128,7 @@ expectAssignable<SelectComponentSchema>({
id: 'yejak',
type: 'select',
dataSrc: 'values',
dataType: 'string',
// basic tab
label: 'Some select',
key: 'someSelect',
Expand Down

0 comments on commit a638bf3

Please sign in to comment.