diff --git a/src/question_baseselect.ts b/src/question_baseselect.ts index 1d3391593e..f55bdcd3d7 100644 --- a/src/question_baseselect.ts +++ b/src/question_baseselect.ts @@ -1338,7 +1338,7 @@ export class QuestionSelectBase extends Question { for (var i = 0; i < this.dependedQuestions.length; i++) { const q = this.dependedQuestions[i]; q.onVisibleChoicesChanged(); - q.clearIncorrectValuesCore(); + q.clearIncorrectValues(); } this.isUpdatingChoicesDependedQuestions = false; } @@ -1426,11 +1426,11 @@ export class QuestionSelectBase extends Question { } protected clearIncorrectValuesCore() { var val = this.value; - if (this.canClearValueAnUnknow(val)) { + if (this.canClearValueAnUnknown(val)) { this.clearValue(); } } - protected canClearValueAnUnknow(val: any): boolean { + protected canClearValueAnUnknown(val: any): boolean { if (!this.getStoreOthersAsComment() && this.isOtherSelected) return false; return this.hasUnknownValue(val, true, true, true); } diff --git a/src/question_checkbox.ts b/src/question_checkbox.ts index 5078831366..a133670469 100644 --- a/src/question_checkbox.ts +++ b/src/question_checkbox.ts @@ -260,7 +260,7 @@ export class QuestionCheckboxModel extends QuestionCheckboxBase { if (Array.isArray(val)) { for (var i = 0; i < val.length; i++) { const rVal = this.getRealValue(val[i]); - if (this.canClearValueAnUnknow(rVal)) { + if (this.canClearValueAnUnknown(rVal)) { this.addIntoInvisibleOldValues(rVal); } } @@ -393,7 +393,7 @@ export class QuestionCheckboxModel extends QuestionCheckboxBase { var newValue = []; for (var i = 0; i < val.length; i++) { const rItemVal = this.getRealValue(val[i]); - var isUnkown = this.canClearValueAnUnknow(rItemVal); + var isUnkown = this.canClearValueAnUnknown(rItemVal); if ( (!clearDisabled && !isUnkown) || (clearDisabled && !this.isValueDisabled(rItemVal)) diff --git a/tests/question_baseselecttests.ts b/tests/question_baseselecttests.ts index c831913822..528e8b5e51 100644 --- a/tests/question_baseselecttests.ts +++ b/tests/question_baseselecttests.ts @@ -987,6 +987,20 @@ QUnit.test("Carry Forward and localization, bug#6352", function (assert) { assert.equal(q2.visibleChoices[0].text, "A en"); surveyLocalization.defaultLocale = "en"; }); +QUnit.test("Carry Forward and keepIncorrectValues, bug#6490", function (assert) { + const survey = new SurveyModel({ elements: [ + { type: "dropdown", name: "q1", choices: ["A", "B", "C", "D"] }, + { type: "dropdown", name: "q2", choicesFromQuestion: "q1" } + ] }); + survey.keepIncorrectValues = true; + survey.data = { q1: "A", q2: "X" }; + const q1 = survey.getQuestionByName("q1"); + const q2 = survey.getQuestionByName("q2"); + q1.value = "B"; + assert.equal(q2.value, "X", "keep value"); + survey.doComplete(); + assert.deepEqual(survey.data, { q1: "B", q2: "X" }, "keep value on compete"); +}); QUnit.test("Do not notify survey on changing newItem.value", function ( assert ) {