surveyjs / survey-library

Free JavaScript form builder library with integration for React, Angular, Vue, jQuery, and Knockout.
https://surveyjs.io/form-library
MIT License
4.12k stars 802 forks source link

Dynamic matrix - data load not working #194

Closed rbarata closed 7 years ago

rbarata commented 7 years ago

Dynamic matrixes don't seem to be correctly showing pre-loaded data. I have set up a simplified example which demonstrates the problem: https://drive.google.com/open?id=0BzOpc-0_DXx3cS0yeEhOWERkejQ

In it, I (1) load a very simple template, consisting of a text field and a dynamic matrix that starts with 0 rows (2) load (using survey.data={...} ) a value into the text field and 3 rows into the dynamic matrix (3) render the survey

When viewing the rendered survey, I would expect to see: (a) the text field appearing with the pre-loaded text -- which it does (b) the dynamic matrix appearing with 3 rows populated with the pre-loaded values -- which it doesn't

Also, if "Add Row" is clicked, the values for the first row appear, but further rows appear blank

This problem happens in version 0.10.3, in the Knockout and JQuery variants

rbarata commented 7 years ago

Just to add that I just saw that this issue had already been mentioned in #34. Applied the workaround suggested there -- updating the template on the fly, setting "rowCount" to the actual number of rows in the data being preloaded for each question of type "matrixdynamic" -- and it worked correctly.

So, I no longer need this fix.

Thanks, Rui

andrewtelnov commented 7 years ago

@rbarata Added a functionality that will increase the rowCount if the value array length is bigger. The new unit test is self-explaining: https://github.com/andrewtelnov/surveyjs/commit/faa9a89238f5ec0af8e8b9fdb27198639f56c683

rbarata commented 7 years ago

Great, thanks!

Regards, Rui

zakpucci commented 5 months ago

@andrewtelnov I'm seeing this happen in the latest survey-react-ui package. Any thoughts? I've tried the patch @rbarata mentioned above and it's still not working. Seems like a race condition, my survey progress is at 100% visually, and the matrix is filled in properly, if any question on the page changes, the progress hits 100 and the dynamic matrix rows correct themselves.