Question T4306
Visible to All Users

getAllQuestions return wrong value

created 5 years ago

Hi, I made a survey in wich i have this structure :

page
panel1
panel2
question1

question1 is in panel2, panel2 is in panel1. When i call getAllQuestions, i receive 2 question1. Is it possible to receive only one question1 because i must validate that all questions as a unique name by code like this :

// Validate duplicate question name
const questionsName: string[] = [];
console.log(this.surveyCreator.getAllQuestions());
this.surveyCreator.getAllQuestions().forEach(question => {
if (questionsName.includes(question.name)) {
if (this.localeId === 'fr-ca') {
error = 'Plus d'une question porte le nom ' + question.name + '. Chaque question doit avoir un nom unique.';
} else {
error = 'More than one question has the name ' + question.name + '. Each question must have a unique name.';
}
currentErrors.push(error);
} else {
questionsName.push(question.name);
}
});

Answers approved by surveyjs Support

created 5 years ago

Hello Eric,
I can't reproduce the issue. Here is the example. Could you please tell us the steps to reproduce the issue?

Thank you,
Andrew
SurveyJS Team

    Show previous comments (7)

      Eric, it should be: this.surveyCreator.survey.getAllQuestions();

      Thank you,
      Andrew
      SurveyJS Team

        Thanks this work well

          Great!

          Andrew
          SurveyJS Team

          created 5 years ago

          Hello Eric,
          It works fine to me. Could you please modify the JSON so it produce the issue. Here is the example.

          Thank you,
          Andrew
          SurveyJS Team

            Comments (1)

              I found one probleme. I open an existing survey. Actually i have question1, question2, question3. Add add question4 and remove question4 immediatly. When i save survey, getAllQuestions return question1, question2, question3 and question4. Why question4 ??? Also here's my json. I don't know why but this json show me question5 2 times.

              {
              "logo": "http://localhost:4210/images/logo-[CODEGEO].png",
              "pages": [
              {
              "name": "page1",
              "elements": [
              {
              "type": "text",
              "name": "question2"
              },
              {
              "type": "matrixdynamic",
              "name": "question1",
              "columns": [
              {
              "name": "id",
              "cellType": "text",
              "visibleIf": "false",
              "codification": "LOCCID"
              },
              {
              "name": "Colonne 2"
              },
              {
              "name": "Colonne 3"
              }
              ],
              "choices": [
              1,
              2,
              3,
              4,
              5
              ],
              "codification": "COMM"
              },
              {
              "type": "panel",
              "name": "panneau1",
              "elements": [
              {
              "type": "matrixdynamic",
              "name": "question3",
              "columns": [
              {
              "name": "id",
              "cellType": "text",
              "visibleIf": "false",
              "codification": "LOCCID"
              },
              {
              "name": "Colonne 2"
              },
              {
              "name": "Colonne 3",
              "cellType": "text"
              }
              ],
              "choices": [
              1,
              2,
              3,
              4,
              5
              ],
              "codification": "COMMINCL"
              }
              ]
              },
              {
              "type": "matrixdynamic",
              "name": "question4",
              "columns": [
              {
              "name": "id",
              "cellType": "text",
              "visibleIf": "false\n",
              "codification": "LOCCID"
              },
              {
              "name": "Colonne 2"
              },
              {
              "name": "Colonne 3"
              }
              ],
              "choices": [
              1,
              2,
              3,
              4,
              5
              ],
              "codification": "COMM"
              },
              {
              "type": "panel",
              "name": "panneau3",
              "elements": [
              {
              "type": "panel",
              "name": "panneau2",
              "elements": [
              {
              "type": "matrixdynamic",
              "name": "question5",
              "columns": [
              {
              "name": "Colonne 1"
              },
              {
              "name": "Colonne 2"
              },
              {
              "name": "Colonne 3"
              }
              ],
              "choices": [
              1,
              2,
              3,
              4,
              5
              ]
              }
              ]
              }
              ]
              }
              ]
              }
              ]
              }