Skip to content

Commit

Permalink
Trigger doesn't work correctly when expression is used checkbox with …
Browse files Browse the repository at this point in the history
…'valuePropertyName' set fix #8434 (#8435)
  • Loading branch information
andrewtelnov authored Jun 18, 2024
1 parent 17d4c75 commit c393f8f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,17 @@ export class Trigger extends Base {
}
protected getUsedVariables(): string[] {
if(!this.conditionRunner) return [];
return this.conditionRunner.getVariables();
const res = this.conditionRunner.getVariables();
if(Array.isArray(res)) {
const unw = "-unwrapped";
for(let i = res.length -1; i >= 0; i--) {
const s = res[i];
if(s.endsWith(unw)) {
res.push(s.substring(0, s.length - unw.length));
}
}
}
return res;
}
private createConditionRunner() {
if (!!this.conditionRunner) return;
Expand Down
41 changes: 41 additions & 0 deletions tests/question_baseselecttests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2119,3 +2119,44 @@ QUnit.test("dropdown.clearValue(true) for showCommentArea & showOtherItem, bug#8
assert.equal(q4.value, undefined, "q4.value");
assert.notOk(q4.comment, "q4.comment");
});
QUnit.test("valuePropertyName & complete trigger, bug#8434", (assert) => {
const survey = new SurveyModel({
"pages": [
{
"name": "page1",
"elements": [
{
"type": "checkbox",
"name": "models",
"choices": [1, 2, 3],
"showNoneItem": true,
"valuePropertyName": "model_id"
}
]
},
{
"name": "page2",
"elements": [
{
"type": "text",
"name": "question1"
}
]
}
],
"triggers": [
{
"type": "complete",
"expression": "{models-unwrapped} = ['none']"
}
]
});
const q = <QuestionCheckboxModel>survey.getQuestionByName("models");
assert.equal(survey.calcIsCompleteButtonVisible(), false, "#1");
q.renderedValue = ["none"];
assert.equal(survey.calcIsCompleteButtonVisible(), true, "#2");
q.renderedValue = [1];
assert.equal(survey.calcIsCompleteButtonVisible(), false, "#3");
q.renderedValue = ["none"];
assert.equal(survey.calcIsCompleteButtonVisible(), true, "#4");
});

0 comments on commit c393f8f

Please sign in to comment.