Issue T2531
Visible to All Users

editor.object.parent is undefined even when editor.object is a question inside a panel

created 5 years ago

Hello,

We are in the process of updating from survey-editor to survey-creator, and we have hit a problem. With this function:

JavaScript
var CustomTextEditorWidget = { render: function(editor, htmlElement) { //code for rendering custom property editor }, validate: function(editor, newValue) { if (!newValue) return null; if (newValue.length < 2) return "Length is less than 2"; if (newValue.length > 5) return "Length is more than 5"; return null; } };

We use editor.object to create some logic for our render function. One of the things we want to know is whether editor.object is inside a panel. Previously, !object.parent || object.parent.isPage would return true if a question is not inside a panel, and false if it was inside a panel. Since the update, this does not work, because even when a question is inside a panel, object.parent is undefined.

Answers approved by surveyjs Support

created 5 years ago

Hello Helen,
Is any chance to get an example or more code so we can understand the reason of issue?

Thank you,
Andrew
SurveyJS Team

    Show previous comments (7)

      I looked at our code. Unfortunately, I do not see any workaround for the current version. Property Editor doesn't know about the original editable question. They are working with it's copied version. We will have to add an originalObject property to Property Editor class. So you will have to use editor.originalObject instead of editor.object.
      We will try to add this property before the next minor release on next week. I am converting this question into the issue.

      Thank you,
      Andrew
      SurveyJS Team

        Helen,
        I have fixed the bug via this commit. I decided do not introduce a new property, and instead set the parent property into the copied object from the original object. Your code should work from v1.1.6 that we will release on the next week.
        I have added the required unit test, to make sure we do not break this code again.

        Thank you,
        Andrew
        SurveyJS Team

          Hello,

          Unfortunately we faced another issue - https://surveyjs.answerdesk.io/ticket/details/t2550
          After investigations we've decided that editor.object property can be undefined during the render function call. Please take it in account during further work. Parent property should be still fixed.

          Thanks, Serge
          SurveyJS Team