Question T9921
Visible to All Users

defaultValueExpression not executed when Survey displayed

created 3 years ago (modified 3 years ago)

Dear support,

I have encountered a problem, that I do not know how to solve. We have a solution, where we create Questionnaires using Survey Creator, populate the input and display the result for people to fill in. The situation is that when I use the Survey Creator and add the value "currentDate()" in defaultValueExpression field, it displays everything correctly - the field is automatically filled with the current date. BUT when I open the same Survey in Viewer, the values are not filled in.

Used Libraries:
"survey-react": "^1.9.6",
"survey-core": "^1.9.6",
"survey-creator-react": "^1.9.6-beta.1"
Unfortunately updating the libraries to latest version did not solve the problem.

Example JSON of the Survey:
{
"logoPosition": "right",
"pages": [
{
"name": "Page1",
"elements": [
{
"type": "text",
"name": "Frage2",
"title": "Ausfülldatum",
"defaultValueExpression": "currentDate()"
}
]
}
]
}
The value of "defaultValueExpression": "currentDate()" exists in all states of the Survey, but when displaying it, it does not execute and the field stays empty. I'm guessing there is a mistake on the way how we render the Component:

Code
//imports export default class Questionnaire extends Component { constructor(props, context) { super(props); Survey.Survey.cssType = "bootstrap"; Survey.defaultBootstrapCss.navigationButton = "btn btn-primary success"; Survey.showNavigationButtons = false; const germanLocalization = Survey.surveyLocalization.locales.de; germanLocalization.addPanel = "Hinzufügen"; germanLocalization.noEntriesText = "Es sind noch keine Einträge vorhanden.\nKlicken Sie auf den Button um einen neuen Eintrag hinzuzufügen."; germanLocalization.fileDragAreaPlaceholder = "Ziehen Sie eine Datei hierher oder klicken Sie auf den Button um eine Datei auszuwählen."; Survey.StylesManager.applyTheme("defaultV2"); this.state = { surveyIsSaved: false, }; } // some other code render() { return ( <Survey.Survey json={this.props.surveyJson} onAfterRenderQuestion={this.onAfterRenderQuestion} data={this.props.surveyData} onCompleting={this.onBeforeCompleting} locale="de" surveyCss="bootstrapmaterial" onValueChanged={this.props.cachingData} mode={this.props.surveyDisplayMode} /> ); } }

Any ideas what needs to be considered would be very helpful!. If you need more Information, just let me know!
Best wishes
Karina

Answers approved by surveyjs Support

created 3 years ago

Hello,
We do not allow to modify any question value if survey in read-only mode. There were a discussion about it and we decided to go this way.
If you want to execute defaultValueExpressions, then do not set display mode immediately and set it after loading the survey.

Modifying question values in read-only survey is not a correct behavior. Most developers do not expect this.

Thank you,
Andrew
SurveyJS Team