diff --git a/libs/shared/src/lib/survey/creator.ts b/libs/shared/src/lib/survey/creator.ts index 23e5bed807..a64d68956b 100644 --- a/libs/shared/src/lib/survey/creator.ts +++ b/libs/shared/src/lib/survey/creator.ts @@ -8,7 +8,6 @@ import { Question } from './types'; export const initCreatorSettings = (): void => { const serializer: JsonMetadata = Serializer; - serializer.findProperty('question', 'name').readOnly = true; serializer.findProperty('question', 'name').onGetValue = (obj: Question) => obj.valueName ? obj.valueName : obj.name; serializer.findProperty('question', 'valueName').isRequired = true; diff --git a/libs/shared/src/lib/survey/global-properties/others.ts b/libs/shared/src/lib/survey/global-properties/others.ts index 4ee0b196c6..15064ff207 100644 --- a/libs/shared/src/lib/survey/global-properties/others.ts +++ b/libs/shared/src/lib/survey/global-properties/others.ts @@ -63,6 +63,24 @@ export const init = (environment: any): void => { } return newValue; }; + // When updating the question name, we need to inform that's a new name + Serializer.addProperty('question', { + name: 'oldName', + visible: false, + }); + // When updating the question name, sets the question valueName as well + serializer.getProperty('question', 'name').onSettingValue = ( + question: Question, + newValue: string + ) => { + if (newValue && question.name && newValue !== question.name) { + question.setPropertyValue('oldName', question.name); + } else { + question.setPropertyValue('oldName', undefined); + } + question.setPropertyValue('valueName', newValue); + return newValue; + }; // Adds valueExpression to questions, that when set pretty much transforms it into an expression question // whilst still keeping normal question behaviors Serializer.addProperty('question', {