Skip to content

Commit

Permalink
Maximum call stack size exceeded at ItemValue.Base exception occurs fix
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtelnov committed May 3, 2024
1 parent 471a864 commit 3b8bc37
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/question_baseselect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export class QuestionSelectBase extends Question {
return "itemvalue";
}
public createItemValue(value: any, text?: string): ItemValue {
const res = <ItemValue>Serializer.createClass(this.getItemValueType(), value);
const res = <ItemValue>Serializer.createClass(this.getItemValueType(), { value: value });
res.locOwner = this;
if(!!text) res.text = text;
return res;
Expand Down Expand Up @@ -1174,18 +1174,29 @@ export class QuestionSelectBase extends Question {
? this.filteredChoicesValue
: this.activeChoices;
}
private isGettingAcitveChoices: boolean;
protected get activeChoices(): Array<ItemValue> {
if(this.isGettingAcitveChoices) return [];
this.isGettingAcitveChoices = true;
let res: Array<ItemValue> = undefined;
const question = this.getCarryForwardQuestion();
if (this.carryForwardQuestionType === "select") {
(<QuestionSelectBase>question).addDependedQuestion(this);
return this.getChoicesFromSelectQuestion((<QuestionSelectBase>question));
res = this.getChoicesFromSelectQuestion((<QuestionSelectBase>question));
} else {
if (this.carryForwardQuestionType === "array") {
(<any>question).addDependedQuestion(this);
res = this.getChoicesFromArrayQuestion(question);
}
}
if (this.carryForwardQuestionType === "array") {
(<any>question).addDependedQuestion(this);
return this.getChoicesFromArrayQuestion(question);
if(!res && this.isEmptyActiveChoicesInDesign) {
res = [];
}
if(this.isEmptyActiveChoicesInDesign) return [];
return this.choicesFromUrl ? this.choicesFromUrl : this.getChoices();
if(!res) {
res = this.choicesFromUrl ? this.choicesFromUrl : this.getChoices();
}
this.isGettingAcitveChoices = false;
return res;
}
public get isMessagePanelVisible(): boolean {
return this.getPropertyValue("isMessagePanelVisible", false);
Expand Down
26 changes: 26 additions & 0 deletions tests/question_baseselecttests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1507,6 +1507,32 @@ QUnit.test("Allow to override default value fro choicesByUrl.path Bug#6766", fun
assert.equal(q1.choicesByUrl.path, "list", "get new default value for path");
prop.defaultValue = undefined;
});
QUnit.test("Infinitive loop error by using carryForward, Bug#8232", function (assert) {
const survey = new SurveyModel({ elements: [
{
type: "checkbox",
name: "q1",
visibleIf: "{q1} notempty",
choices: [{ value: 1, text: "Item 1" }, { value: 2, text: "Item 2" }, { value: 3, text: "Item 3" },
{ value: 4, text: "Item 4" }, { value: 5, text: "Item 5" }],
choicesFromQuestionMode: "selected",
hideIfChoicesEmpty: true,
},
{
type: "checkbox",
name: "q2",
choicesFromQuestion: "q1",
choicesFromQuestionMode: "unselected",
hideIfChoicesEmpty: true,
}],
});
const q1 = <QuestionCheckboxModel>survey.getQuestionByName("q1");
const q2 = <QuestionCheckboxModel>survey.getQuestionByName("q2");
assert.ok(q1, "q1 exists");
assert.ok(q2, "q2 exists");
assert.equal(q1.visibleChoices.length, 5, "q1.visibleChoices");
assert.equal(q2.visibleChoices.length, 5, "q2.visibleChoices");
});
QUnit.test("Use carryForward with panel dynamic + choiceValuesFromQuestion + valueName, Bug#6948-1", function (assert) {
const survey = new SurveyModel({ elements: [
{ type: "paneldynamic", name: "q1", valueName: "sharedData",
Expand Down

0 comments on commit 3b8bc37

Please sign in to comment.