Skip to content

Commit

Permalink
survey.onValueChanged is not fired on changing question comment if va…
Browse files Browse the repository at this point in the history
…lueName property is used fixed #8137 (#8138)
  • Loading branch information
andrewtelnov committed Apr 18, 2024
1 parent aabd758 commit c328a21
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/survey.ts
Expand Up @@ -6594,11 +6594,7 @@ export class SurveyModel extends SurveyElementCore
* @param locNotification For internal use.
* @see getComment
*/
public setComment(
name: string,
newValue: string,
locNotification: any = false
) {
public setComment(name: string, newValue: string, locNotification: any = false):void {
if (!newValue) newValue = "";
if (this.isTwoValueEquals(newValue, this.getComment(name))) return;
var commentName = name + this.commentSuffix;
Expand All @@ -6620,7 +6616,7 @@ export class SurveyModel extends SurveyElementCore
if (locNotification !== "text") {
this.tryGoNextPageAutomatic(name);
}
var question = this.getQuestionByName(name);
var question = this.getQuestionByValueName(name);
if (question) {
this.onValueChanged.fire(this, {
name: commentName,
Expand Down
39 changes: 39 additions & 0 deletions tests/question_baseselecttests.ts
Expand Up @@ -1873,4 +1873,43 @@ QUnit.test("radiogroup with incorrect defaultValue, other & survey.data Bug#7943
assert.deepEqual(survey.data, { q1: "other", "q1-Comment": "101" }, "survey.data");
survey.doComplete(false);
assert.deepEqual(survey.data, { q1: "other", "q1-Comment": "101" }, "survey.data on complete");
});
QUnit.test("On value changed, comment and valueName Bug#8137", (assert) => {
const survey = new SurveyModel({
"elements": [
{
"type": "radiogroup",
"name": "q1",
"valueName": "val1",
"choices": [1, 2],
"showOtherItem": true,
}
]
});
let counter = 0;
let questionName = "";
let name = "";
let value = undefined;
survey.onValueChanged.add((sender, options) => {
counter ++;
questionName = options.question.name;
name = options.name;
value = options.value;
});
const q = <QuestionRadiogroupModel>survey.getQuestionByName("q1");
q.value = 1;
assert.equal(counter, 1, "counter #1");
assert.equal(questionName, "q1", "question.name #1");
assert.equal(name, "val1", "name #1");
assert.equal(value, 1, "value #1");
q.value = "other";
assert.equal(counter, 2, "counter #2");
questionName = "";
name = "";
value = undefined;
q.comment = "comment1";
assert.equal(counter, 3, "counter #3");
assert.equal(questionName, "q1", "question name #3");
assert.equal(name, "val1-Comment", "name #3");
assert.equal(value, "comment1", "value #3");
});

0 comments on commit c328a21

Please sign in to comment.