Skip to content

Commit

Permalink
Merge pull request #8607 from surveyjs/bug/8603-displayvalue-value-0
Browse files Browse the repository at this point in the history
The displayValue('questionName', questionValue) function produces a w…
  • Loading branch information
OlgaLarina authored Jul 25, 2024
2 parents d1122f2 + 4b151f2 commit d5e402e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/functionsfactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ function getQuestionValueByContext(context: any, name: string): any {
function displayValue(params: any[]): any {
const q = getQuestionValueByContext(this, params[0]);
if(!q) return "";
if(params.length > 1 && !!params[1]) return q.getDisplayValue(true, params[1]);
if(params.length > 1 && !Helpers.isValueEmpty(params[1])) return q.getDisplayValue(true, params[1]);
return q.displayValue;
}
FunctionFactory.Instance.register("displayValue", displayValue);
Expand Down
29 changes: 29 additions & 0 deletions tests/surveytests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18883,6 +18883,35 @@ QUnit.test("Test displayValue() function with value parameter", function (assert
assert.equal(rows[2].cells[1].value, "Item check 1", "cells[2,1].value");
assert.equal(rows[2].cells[2].value, "Item 1", "cells[2,2].value");
});
QUnit.test("Test displayValue() function with value parameter & 0 value, Bug#8603", function (assert) {
const survey = new SurveyModel({
elements: [
{
type: "checkbox",
name: "q1",
choices: [{ value: 0, text: "Item check 0" }, { value: 1, text: "Item check 1" }, { value: 2, text: "Item check 2" }]
},
{
type: "matrixdynamic",
name: "matrix",
columns: [
{ cellType: "text", name: "col1" },
{ cellType: "expression", name: "col2", expression: "displayValue('q1', {row.col1})" }
]
}
]
});
survey.setValue("q1", [0, 1, 2]);
const matrix = survey.getQuestionByName("matrix");
matrix.rowCount = 3;
const rows = matrix.visibleRows;
rows[0].cells[0].value = 0;
rows[1].cells[0].value = 1;
rows[2].cells[0].value = 2;
assert.equal(rows[0].cells[1].value, "Item check 0", "cells[0,1].value");
assert.equal(rows[1].cells[1].value, "Item check 1", "cells[1,1].value");
assert.equal(rows[2].cells[1].value, "Item check 2", "cells[2,1].value");
});
QUnit.test("Test propertyValue() function", function (assert) {
const survey = new SurveyModel({
elements: [
Expand Down

0 comments on commit d5e402e

Please sign in to comment.