question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`clearInvisibleValues: 'onHidden'` makes survey nullify some question values while loading data

See original GitHub issue

Are you requesting a feature, reporting a bug or asking a question?

question

What is the current behavior?

I need to use clearInvisibleValues: 'onHidden' (it’s a requirement) but when I use visibleIf targeting a question whose value depends on some async events I got an undesired behaviour. I created a plunk to show this

https://plnkr.co/edit/YQxFPTAsv0zgz0R0

If you rerun the survey multiple times you’ll see that foo question loses its initial value. Looking at the console you’ll see how the survey data evolves. In my understanding there is a moment when copyCountry gets null and, as a consequence, foo gets undefined too. Is this explanation correct? Of course, removing clearInvisibleValues: 'onHidden' solves but for me it is essential when the user interact with the survey. To be more precise I don’t need it in the “data loading phase” while I need it later during user interaction. I think this survey property can be changed at runtime but how can I know when surveyJS has finished to run all expressions and choicesByUrl stuff and its ready for editing? This leads me again to this old unresolved issue https://github.com/surveyjs/survey-library/issues/1871

Curiously this does not happen without paneldynamic.

https://plnkr.co/edit/vaqoo5Xnnwmf1pYZ

Is this all expected?

thanks a lot

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
gologamescommented, Jul 3, 2020

Hello,

Let me, please, explain my thoughts about this situation. I think there is no way to solve this problem in general case on SurveyJS side. Just because there is an dependency graph (not tree) in general case

E.g. I modified your plunker. I set the expression question calculate value equal to text question. And text question visible if expression is not empty. Also clearInvisibleValues on hidden. What we got?

Let’s imagine case 1:

  1. Set data value to text questions
  2. Clear text value due to clearInvisibleValues
  3. Copy empty value from text to expression
  4. Hide text question due to expression is empty

Otherwise imagine case 2:

  1. Set data value to text questions
  2. Copy not empty value from text to expression
  3. Display text question due to expression is not empty
  4. clearInvisibleValues call has no effect

What of this these two cases is true? No answer. There is no right case. So this problem hasn’t solution in general case with that amount of information which we have at SurveyJS library side

So as a result I can suggest you process your business logic with various SurveyJS events such as onValueChanged or onVisibleChanged. You can also count loaded questions to detect when survey is loaded according to your business logic

Thanks, Alex SurveyJS Team

0reactions
gologamescommented, Jul 3, 2020

Hello,

@gologames I don’t understand what you mean. In my case, having a defaultValue specified and having the field on visibleIf depending on another field, when the field is hidden, there should be no value, but when the field is shown, it should have the defaultValue (if defined). I don’t see a problem with this case but please elaborate if there is an issue. When I think back to how this used to work, I think it worked like this and the functionality disappeared some time ago (I would have to test with older survey.jquery file versions to see if I’m correct).

In your case the situation is absolutely the same as I described above Imagine this case:

  1. Default value is set for question which is hidden due to visible if
  2. Value of this question clears due to clearInvisibleValues
  3. Then visible if becames true
  4. Question displays with empty data

This is one of valid scenarios. You can use onVisibleChanged event to set question value equal to default value when question will became visible

Thanks, Alex SurveyJS Team

Read more comments on GitHub >

github_iconTop Results From Across the Web

Problem with clearInvisibleValues: "onHidden" not working
I am using "surveyjs - Survey JavaScript library v1.7.15". I have set the property to "onHidden". But visibleIf questions retain their answers ...
Read more >
QuestionNonValue
A base class for question types that cannot have a value (Html, Image). This class does not implement new functionality—it only redefines default...
Read more >
survey-knockout/survey.ko.d.ts
353, clearFiles(question: IQuestion, name: string, value: any, fileName: string, clearCallback: (status: string, data: any) => any): any;.
Read more >
implement select2 tagbox in reactjs from surveyjs
hi im using the surveyjs to create my react survey and there is a question ... clearInvisibleValues: "onHidden", questions: [ { //question 1 ......
Read more >
survey.angular.d.ts - jsDelivr
@see data * @see clearInvisibleValues * @see completeLastPage * @see ... </br> Set it to 'onHidden' to clear the question value when it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found