From e482fdcafc8bc8219e6f44fee18d0ff52a1fe07e Mon Sep 17 00:00:00 2001 From: Andrew Telnov Date: Fri, 30 Jul 2021 15:32:49 +0300 Subject: [PATCH] Fix: Do not call notification on setting the same value in select base renderedValue property #3160 --- src/question_baseselect.ts | 5 +++- tests/question_matrixdynamictests.ts | 39 ++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/question_baseselect.ts b/src/question_baseselect.ts index 1a69b61176..7cb4bb71a3 100644 --- a/src/question_baseselect.ts +++ b/src/question_baseselect.ts @@ -342,7 +342,10 @@ export class QuestionSelectBase extends Question { } public set renderedValue(val: any) { this.setPropertyValue("renderedValue", val); - this.value = this.rendredValueToData(val); + var val = this.rendredValueToData(val); + if (!Helpers.isTwoValueEquals(val, this.value)) { + this.value = val; + } } protected setQuestionValue( newValue: any, diff --git a/tests/question_matrixdynamictests.ts b/tests/question_matrixdynamictests.ts index 5d605d90f5..5e2eda41c0 100644 --- a/tests/question_matrixdynamictests.ts +++ b/tests/question_matrixdynamictests.ts @@ -6765,3 +6765,42 @@ QUnit.test( assert.equal(counter, 1, "value is correct"); } ); +QUnit.test( + "Matrixdynamic onMatrixValueChanging - do not call event on set the same renderedValue", + function(assert) { + var json = { + questions: [ + { + type: "matrixdynamic", + name: "q1", + rowCount: 1, + columns: [ + { + name: "col1", + choices: [1, 2, 3, 4, 5], + }, + ], + }, + ], + }; + var survey = new SurveyModel(json); + var counter = 0; + survey.onMatrixCellValueChanging.add(function(sender, options) { + counter++; + }); + var matrix = survey.getQuestionByName("q1"); + var cellQuestion = ( + matrix.visibleRows[0].cells[0].question + ); + cellQuestion.renderedValue = undefined; + assert.equal(counter, 0, "There is not value to clear"); + cellQuestion.renderedValue = 1; + assert.equal(counter, 1, "Call one time"); + cellQuestion.renderedValue = 1; + assert.equal(counter, 1, "Do not call on the same value"); + cellQuestion.renderedValue = undefined; + assert.equal(counter, 2, "Value is undefined"); + cellQuestion.renderedValue = undefined; + assert.equal(counter, 2, "Value is still undefined"); + } +);