Survey-library: Track non-visible questions in `survey.data`

Created on 22 Sep 2017  路  10Comments  路  Source: surveyjs/survey-library

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

Requesting a feature

What is the current behavior?

Questions that are not visible & have no answer are not tracked in survey.data

What is the expected behavior?

That is the expected behavior... for now. I'd love it if EVERY question in the supplied JSON was persisted in the survey.data, regardless of it there has been an answer supplied. Defaulting it to null would be super helpful.

How would you reproduce the current behavior (if this is a bug)?

Specify your

  • browser:
  • browser version:
  • surveyjs platform (angular or react or jquery or knockout or vue): jQuery
  • surveyjs version: v0.12.1

If you could point me in the right direction, I can help contribute to making this happen! (if it is desired by others, I'll do a pull request)

Most helpful comment

@mellogarrett This is what you mean: https://plnkr.co/edit/5g3cingxtK8kczg7YD7n?p=preview

Thank you,
Andrew

All 10 comments

@mellogarrett The most people ask for opposite. Do you want to have the null value in JSON to be posted on server?
In this case, you may just write code onComplete event, go through all questions (survey.getAllQuestions()) and if survey.getValue(question.name) returns null add the requried field into JSON result.

Thank you,
Andrew

I understand the major need, but I think that is mainly related to the fact that the json survey data is usually stored as-is as a whole. This means that it can be simply replaced in case of update of the survey. But if you need to save pieces of survey data separately it would be much more useful to get null values in order to catch the changes immediately because no data often means "nothing changed" but if a field or a whole panel become null it actually changed! I would like to have a very high level control in order to enable my survey returning null everywhere as cycling by survey.getAllQuestions could be hard when matrix came into play. Long live surveyJS!

@masciugo SurveyJS gives you 3 choices now. Please look at this help topic: https://surveyjs.io/Documentation/Library/?id=surveymodel#clearInvisibleValues'

Thank you,
Andrew

thank you Andrew. Even if this feature is very helpfull it solves partially my use case as it does not consider _empty_ values (no answer) as described in this issue. I think about text field that become blank at later time. How can I catch the change? (Hope my concern can be helpful for the whole project development too)

@masciugo The technical problem, that setting the value to null/empty string, currently equals, to clearing the value, removing it from Survey.data.
You may add a function onValueChanged event and create a value name hash with empty values.
onComplete survey event add into survey.data those value names with null value, if they are not already exists.
It should solved the issue. Let me know if you need a help with it.

Thank you,
Andrew

ok it makes sense but with survey-react empty object is showed as [object Object] in the input field.

https://plnkr.co/edit/sp67Avwta1CbFzEHTbs0?p=preview

I can use another char to mean absence of data like a dash. Thanks a lot

@mellogarrett This is what you mean: https://plnkr.co/edit/5g3cingxtK8kczg7YD7n?p=preview

Thank you,
Andrew

a small improvement to deal with empty array as question value

https://plnkr.co/edit/LFjMZiWXNZn8YrPyYjIt?p=preview

reference @andrewtelnov, but something difference: remove nullableValues and survey
.onValueChanged....
link

@Beannn Sorry, I do not understand what do you want to do, could you explain in more details?

Thank you,
Andrew

Was this page helpful?
0 / 5 - 0 ratings