Skip to content

Commit

Permalink
Expression question display defaultValue instead of empty string fix #…
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtelnov authored Nov 14, 2023
1 parent 65b8898 commit e16688e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/question_expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export class QuestionExpressionModel extends Question {
this.updateFormatedValue();
}
protected getDisplayValueCore(keysAsText: boolean, value: any): any {
var val = this.isValueEmpty(value) ? this.defaultValue : value;
var val = value === undefined || value === null ? this.defaultValue : value;
var res = "";
if (!this.isValueEmpty(val)) {
var str = this.getValueAsStr(val);
Expand Down
17 changes: 17 additions & 0 deletions tests/question_expressiontests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,3 +296,20 @@ QUnit.test("Custom function returns object&array, #7050", function (assert) {
FunctionFactory.Instance.unregister("func1");
FunctionFactory.Instance.unregister("func2");
});
QUnit.test("Default value and setValueExpression", function (assert) {
const survey = new SurveyModel({
elements: [
{ type: "expression", name: "q1", setValueExpression: "iif({q2} = 1, 'b', ''", defaultValue: "a" },
{ type: "text", name: "q2" }
]
});
const q1 = survey.getQuestionByName("q1");
assert.equal(q1.value, "a", "default value is 'a'");
assert.equal(q1.formatedValue, "a", "formatedValue, default value is 'a'");
survey.setValue("q2", 1);
assert.equal(q1.value, "b", "var1 = 1");
assert.equal(q1.formatedValue, "b", "formatedValue, var1 = 1");
survey.setValue("q2", 2);
assert.equal(q1.value, "", "var1 = 2");
assert.equal(q1.formatedValue, "", "formatedValue, var1 = 2");
});

0 comments on commit e16688e

Please sign in to comment.