surveyjs / survey-library

Free JavaScript form builder library with integration for React, Angular, Vue, jQuery, and Knockout.
https://surveyjs.io/form-library
MIT License
4.03k stars 787 forks source link

Panel dynamic addConditionObjectsByContext function doesn't work correctly for a question in the nested panel dynamic #8186

Closed andrewtelnov closed 3 months ago

andrewtelnov commented 3 months ago

If there is a panel dynamic placed inside another dynamic panel then addConditionObjectsByContext doesn't work correctly. The following unit test doens't work, tests objs[2] gives the error:

const survey = new SurveyModel({
    "elements": [
      {
        "type": "paneldynamic",
        "name": "question1",
        "title": "parent dynamic panel",
        "templateElements": [
          {
            "type": "paneldynamic",
            "name": "question2",
            "title": "nested dynamic panel",
            "templateElements": [
              {
                "type": "text",
                "name": "question3",
                "title": "nq1"
              },
              {
                "type": "text",
                "name": "question4",
                "title": "nq2"
              }
            ]
          },
          {
            "type": "text",
            "name": "question5",
            "title": "pq1"
          }
        ]
      }
    ]
  });
  const rootPanel = survey.getQuestionByName("question1");
  const nestedPanel = rootPanel.template.getQuestionByName("question2");
  const question3 = nestedPanel.template.getQuestionByName("question3");
  const objs: IConditionObject[] = [];
  rootPanel.addConditionObjectsByContext(objs, question3);
  assert.equal(objs.length, 4, "There should be 4 elements");
  assert.equal(objs[0].name, "question1[0].question2[0].question3", "value #0");
  assert.equal(objs[1].name, "question1[0].question2[0].question4", "value #1");
  assert.equal(objs[2].name, "panel.question4", "value #2");
  assert.equal(objs[2].text, "panel.nq2", "text #2");
  assert.equal(objs[3].name, "question1[0].question5", "value #3");