Skip to content

Commit

Permalink
Default values for carry-forward items. No values fix #8558 (#8559)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtelnov authored Jul 15, 2024
1 parent 28f888f commit 159bf22
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/question_baseselect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2073,6 +2073,7 @@ Serializer.addClass(
return !obj.choicesFromQuestion;
},
},

{
name: "choicesByUrl:restfull",
className: "choicesByUrl",
Expand All @@ -2092,6 +2093,8 @@ Serializer.addClass(
return !obj.choicesFromQuestion;
},
},
{ name: "defaultValue:value", visibleIf: (obj: any): boolean => !obj.choicesFromQuestion, dependsOn: "choicesFromQuestion" },
{ name: "correctAnswer:value", visibleIf: (obj: any): boolean => !obj.choicesFromQuestion, dependsOn: "choicesFromQuestion" },
{ name: "separateSpecialChoices:boolean", visible: false },
{ name: "showOtherItem:boolean", alternativeName: "hasOther" },
{ name: "showNoneItem:boolean", alternativeName: "hasNone" },
Expand Down Expand Up @@ -2151,8 +2154,7 @@ Serializer.addClass(
default: "default",
choices: ["default", true, false],
visible: false,
},
// { name: "itemComponent", visible: false }
}
],
null,
"question"
Expand Down
7 changes: 7 additions & 0 deletions tests/question_baseselecttests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1311,6 +1311,8 @@ QUnit.test("Carry Forward and keepIncorrectValues, bug#6490", function (assert)
});
QUnit.test("Check isUsingCarryForward on deleting question", function (assert) {
const survey = new SurveyModel();
const defaultValueProp = Serializer.findProperty("dropdown", "defaultValue");
const correctAnswerProp = Serializer.findProperty("dropdown", "correctAnswer");
survey.setDesignMode(true);
survey.fromJSON({ elements: [
{ type: "dropdown", name: "q1", choices: ["B", "A", "D", "C"] },
Expand All @@ -1320,9 +1322,14 @@ QUnit.test("Check isUsingCarryForward on deleting question", function (assert) {
const q2 = <QuestionSelectBase>survey.getQuestionByName("q2");
assert.equal(q2.choicesFromQuestion, "q1", "set correctly");
assert.equal(q2.isUsingCarryForward, true, "Carryforward flag is set");
assert.equal(defaultValueProp.isVisible("", q2), false, "defaultValueProp.isVisible #1");
assert.equal(correctAnswerProp.isVisible("", q2), false, "correctAnswerProp.isVisible #1");

q1.delete();
assert.notOk(q2.choicesFromQuestion, "it is empty");
assert.equal(q2.isUsingCarryForward, false, "Carryforward flag is unset");
assert.equal(defaultValueProp.isVisible("", q2), true, "defaultValueProp.isVisible #2");
assert.equal(correctAnswerProp.isVisible("", q2), true, "correctAnswerProp.isVisible #2");
});
QUnit.test("Do not notify survey on changing newItem.value", function (
assert
Expand Down

0 comments on commit 159bf22

Please sign in to comment.