Question T5943
Visible to All Users

problems with the id property on questions (and checkboxes)

created 4 years ago

Hello,
So i'll start with how questions work, and this is me adding the property 'id' on questions :

Survey.Serializer.addProperty("question", {name: "id",category: "general"});
SurveyCreator.SurveyQuestionEditorDefinition.definition["question"].properties.push("id");

Now this code above should put the property 'id' on any question. But … if I try to change the question order by drag and drop, the question disappears from the screen. So this is a bug, or … there must be an alternative to this.

  • Note that when doing the save, the question (and all the survey data) does get correctly passed to the backend

And then there's this :
Survey.Serializer.findProperty("question", "id").visible = false

This doesn't work, it works for any other property except this, it always shows it in the properties list

Going one step further on checkboxes, i've been told in a different ticket, that in order to add a property 'id' to checkboxes, i need to do this :
Survey.Serializer.addProperty("itemvalue", {name: "id",category: "general"});
SurveyCreator.SurveyQuestionEditorDefinition.definition["itemvalue[]@choices"].properties.push("id");

Now this, works perfectly EXCEPT, when i try to hide the ids of choices, by

  1. Survey.Serializer.findProperty("itemvalue", "id").visible = false
  2. Survey.Serializer.findProperty("itemvalue[]@choices", "id").visible = false;

But none of these actually do anything.

Recap : The ids of both questions and choices come generated from the backend, the survey 'creator' should not have access to modifying those ids.

Answers approved by surveyjs Support

created 4 years ago

Hello Alex,
If you want to hide them dynamically then you should use creator.onShowingProperty event. I believe Andy mentioned this event to you.
Otherwise, you can simply hide the property from the beginning:

JavaScript
Survey.Serializer.addProperty("question", {name: "id",category: "general", visible: false});

Thank you,
Andrew
SurveyJS Team

    Comments (2)

      Hello,
      I don't remember if he mentioned it. But yes this visible false makes them not available for the users. Thank you. However the real issue and bug is still there, when moving an element it disappears from the screen(survey creator). So there's a problem with this 'id' on questions. It only disappears when i set it. And i've tried this on Firefox/Chrome in different variations. Even removing all the customization, if i just add this, the way you suggest it :
      Survey.Serializer.addProperty("question", {name: "id",category: "general", visible: false});

      When I move ANY question, it disappears, and in the browser console i get the following :
      Uncaught DOMException: Element.querySelector: '#sq_101' is not a valid selector

      As far as i've noticed,surveyjs defaults it to such values. So … is there an option to have ids on questions without breaking the survey creator? Because at the moment it seems there isn't.

        Arh, indeed. I forgot, you can't use question.id. It is already reserved. Here is the docs. Please use another name.

        Thank you,
        Andrew
        SurveyJS Team