diff --git a/src/openforms/js/compiled-lang/en.json b/src/openforms/js/compiled-lang/en.json
index e2f7fe336b..f0fd88ca93 100644
--- a/src/openforms/js/compiled-lang/en.json
+++ b/src/openforms/js/compiled-lang/en.json
@@ -3909,6 +3909,12 @@
"value": "Login required?"
}
],
+ "af22yB": [
+ {
+ "type": 0,
+ "value": "Changing the data type requires the initial value to be changed. This will reset the initial value back to the empty value. Are you sure that you want to do this?"
+ }
+ ],
"aqYeqv": [
{
"type": 0,
diff --git a/src/openforms/js/compiled-lang/nl.json b/src/openforms/js/compiled-lang/nl.json
index 7354935a39..b440c28c3a 100644
--- a/src/openforms/js/compiled-lang/nl.json
+++ b/src/openforms/js/compiled-lang/nl.json
@@ -3927,6 +3927,12 @@
"value": "Vereist authenticatie"
}
],
+ "af22yB": [
+ {
+ "type": 0,
+ "value": "Het veranderen van het datatype vereist een verandering aan de beginwaarde. Dit zal de beginwaarde terugbrengen naar de standaardwaarde. Weet je zeker dat je dit wilt doen?"
+ }
+ ],
"aqYeqv": [
{
"type": 0,
diff --git a/src/openforms/js/components/admin/form_design/form-creation-form.js b/src/openforms/js/components/admin/form_design/form-creation-form.js
index adc7b4f178..4fdd86bbc9 100644
--- a/src/openforms/js/components/admin/form_design/form-creation-form.js
+++ b/src/openforms/js/components/admin/form_design/form-creation-form.js
@@ -70,6 +70,7 @@ import {
getUniqueKey,
parseValidationErrors,
slugify,
+ transformInitialValue,
updateKeyReferencesInLogic,
updateRemovedKeyInLogic,
} from './utils';
@@ -784,6 +785,14 @@ function reducer(draft, action) {
draft.formVariables[index][propertyName] = propertyValue;
}
+ // When dataType changes, a data transformation is needed
+ if (propertyName === 'dataType') {
+ draft.formVariables[index]['initialValue'] = transformInitialValue(
+ propertyValue,
+ originalVariable.initialValue
+ );
+ }
+
// Check if there are errors that need to be reset
if (draft.formVariables[index].errors) {
const errorKeys = propertyName === '' ? Object.keys(propertyValue) : [propertyName];
@@ -1229,6 +1238,42 @@ const FormCreationForm = ({formUuid, formUrl, formHistoryUrl, outgoingRequestsUr
payload: pluginId,
});
};
+ const onUserDefinedVariableChange = async (key, propertyName, propertyValue) => {
+ const originalVariable = state.formVariables.find(variable => variable.key === key);
+ // Just dispatch if anything other than dataType changes
+ // or if the initialValue is null/undefined
+ if (
+ propertyName !== 'dataType' ||
+ originalVariable?.initialValue == null ||
+ originalVariable?.initialValue === ''
+ ) {
+ dispatch({
+ type: 'CHANGE_USER_DEFINED_VARIABLE',
+ payload: {key, propertyName, propertyValue},
+ });
+ return;
+ }
+
+ // Check if the dataType change is intentional.
+ if (
+ propertyName === 'dataType' &&
+ !window.confirm(
+ intl.formatMessage({
+ description:
+ 'Changing user variable data type and transforming initial value confirmation message',
+ defaultMessage:
+ 'Changing the data type requires the initial value to be changed. This will reset the initial value back to the empty value. Are you sure that you want to do this?',
+ })
+ )
+ ) {
+ return;
+ }
+
+ dispatch({
+ type: 'CHANGE_USER_DEFINED_VARIABLE',
+ payload: {key, propertyName, propertyValue},
+ });
+ };
if (loading || state.submitting) {
return