Question T5913
Visible to All Users

Re: Reinitialise elements in a panel

created 4 years ago

Hello.
Using the panel visibility event, I coded this -

survey.onPanelVisibleChanged.add(
function(_survey, _options) {
var _p = _options.panel.elements;
if (! _options.visible) for (var _i in _p) {if (! (_p[_i] instanceof Function)) {_p[_i].value = undefined;}}
});

It does 'reinit' all elements. Is this the correct approach?

Met vriendelijk groeten.

From: D04105641@inbox.lv
Sent: Sunday, December 13, 2020 10:44 PM
To: Serge T [surveyjs Support]
Subject: Reinitialise elements in a panel

Hello.
I do not find a method to 'reset' the state of elements in a panel. This,
for my purpose, is useful when a different 'entry point' of the navigation
path is selected.

I also do not find an element property that points to the first child
element. 'child -> parent' but not the opposite. Also not self->sibling.

Met vriendelijk groeten,
Max

Answers approved by surveyjs Support

created 4 years ago

Hello Max,
Do you want to clear all questions inside the container (page/panel) on hiding this container?
I am thinking about adding a new option that will do it out of the box.
The correct code is:

JavaScript
survey.onPanelVisibleChanged.add( function(survey, options) { if(options.visible) return; var questions = options.panel.questions; for(var i = 0; i < questions.length; i ++) { questions[i].clearValue(); } });

Thank you,
Andrew
SurveyJS Team

    Show previous comments (3)

      Max,
      Why should you confused by working code?
      panel.elements contains panels and questions, panel.questions in fact it is filtered panel.elements by removing panels. In fact, it is more complicated, due some performance optimizations. Anyway, if you need questions, you should use it.
      clearValue is the function of question that makes value and comment "undefined".

      Thank you,
      Andrew
      SurveyJS Team

        Hello.
        The suggestion has been implemented (question.clearValue() == null).

        Reading the documentation for Question, the method clearValue() is not found. It is found in SurveyModel. It is also (logically) found on GitHub in src/question.ts . This is why the method was not initially used.

        Met vriendelijk groeten.

          Added the documentation for clearValue().

          Thank you,
          Andrew
          SurveyJS Team