Skip to content

Commit

Permalink
Maximum call stack size exceeded at ItemValue.Base exception occurs f… (
Browse files Browse the repository at this point in the history
#8233)

* Maximum call stack size exceeded at ItemValue.Base exception occurs fix #5462

* Rewrite the fix #5462
  • Loading branch information
andrewtelnov authored May 6, 2024
1 parent 0f041a5 commit 648d819
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/actions/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export abstract class BaseAction extends Base implements IAction {
public id: string;
public removePriority: number;
@property() iconName: string;
@property() iconSize: number = 24;
@property({ defaultValue: 24 }) iconSize: number;
@property() css?: string
minDimension: number;
maxDimension: number;
Expand Down
14 changes: 7 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 @@ -482,7 +482,7 @@ export class QuestionSelectBase extends Question {
private canSurveyChangeItemVisibility(): boolean {
return !!this.survey && this.survey.canChangeChoiceItemsVisibility();
}
public changeItemVisisbility() {
private changeItemVisibility() {
return this.canSurveyChangeItemVisibility() ?
(item: ItemValue, val: boolean): boolean => this.survey.getChoiceItemVisibility(this, item, val)
: null;
Expand All @@ -492,7 +492,7 @@ export class QuestionSelectBase extends Question {
properties: HashTable<any>
): boolean {
this.filteredChoicesValue = [];
const calcVisibility = this.changeItemVisisbility();
const calcVisibility = this.changeItemVisibility();
return ItemValue.runConditionsForItems(
this.activeChoices,
this.getFilteredChoices(),
Expand Down Expand Up @@ -1065,7 +1065,7 @@ export class QuestionSelectBase extends Question {
protected canShowOptionItem(item: ItemValue, isAddAll: boolean, hasItem: boolean): boolean {
let res: boolean = (isAddAll && (!!this.canShowOptionItemCallback ? this.canShowOptionItemCallback(item) : true)) || hasItem;
if (this.canSurveyChangeItemVisibility()) {
const calc = this.changeItemVisisbility();
const calc = this.changeItemVisibility();
return calc(item, res);
}
return res;
Expand Down Expand Up @@ -1581,7 +1581,7 @@ export class QuestionSelectBase extends Question {
this.onVisibleChoicesChanged();
this.clearIncorrectValues();
}
onSurveyValueChanged(newValue: any) {
onSurveyValueChanged(newValue: any): void {
super.onSurveyValueChanged(newValue);
this.updateChoicesDependedQuestions();
}
Expand All @@ -1597,8 +1597,8 @@ export class QuestionSelectBase extends Question {
protected isVisibleCore(): boolean {
const superVal = super.isVisibleCore();
if (!this.hideIfChoicesEmpty || !superVal) return superVal;
var filteredChoices = this.getFilteredChoices();
return !filteredChoices || filteredChoices.length > 0;
var choices = this.isUsingCarryForward ? this.visibleChoices : this.getFilteredChoices();
return !choices || choices.length > 0;
}
private sortVisibleChoices(array: Array<ItemValue>): Array<ItemValue> {
if(this.isDesignMode) return array;
Expand Down
27 changes: 27 additions & 0 deletions tests/question_baseselecttests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1507,6 +1507,33 @@ 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");
assert.equal(q2.isVisible, true, "q2 is visible");
});
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 648d819

Please sign in to comment.