Skip to content

Commit

Permalink
honour keepIncorrectValues for choicesFromQuestion dropdown fix #6490
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtelnov committed Jul 10, 2023
1 parent 74c08e8 commit f677ab2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/question_baseselect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/question_checkbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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))
Expand Down
14 changes: 14 additions & 0 deletions tests/question_baseselecttests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <QuestionSelectBase>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
) {
Expand Down

0 comments on commit f677ab2

Please sign in to comment.