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.19k stars 808 forks source link

defaultValue choicesByUrl not defaulting value #1000

Closed edwardrbaker closed 6 years ago

edwardrbaker commented 6 years ago

This is a bug report for a dropdown when a defaultValue is provided along with a choicesByUrl. On initial page load, the defaultValue is not selected from the list after the choices are loaded. Our example has a static list and a dynamic list for you to compare

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

Thanks!

andrewtelnov commented 6 years ago

@erbaker I have added a unit test and could not reproduce the issue. I have created an example and it works fine: https://plnkr.co/edit/37RmsmKLJjtuY0pvcp5a?p=preview You do not use the https://restcountries.eu api correctly.

Thank you, Andrew

edwardrbaker commented 6 years ago

The issue isn't the implementation of the REST API; I have updated your plunkr: https://plnkr.co/edit/3PZPEQwIBWAqM6wDXNlK?p=preview

I would expect that "Chad" is selected in the countries box by default.

edwardrbaker commented 6 years ago

Here is the same plunkr from above but with version 0.12.36

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

mdickin commented 6 years ago

To narrow it down a bit more, it looks like this bug surfaced in the changes from v1.0.1 to v1.0.2.

andrewtelnov commented 6 years ago

@erbaker @mdickin I have fixed the bug. Unfortunately I could not reproduce it in Unit Test. I have added in TODO to add a functional test (TestCafe test). The bug was here all the time in knockout version. We built jQuery based on react version by using preact. Since couple months ago jQuery is built based on knockout version.

Here is what happend. knockout clears a question value on empty dropdown. We have written a workaround for this, but this workaround doesn't work correctly when the value is setting onLoading survey via defaultValue. I have updated our work-around.

The update will be available on the next week.

Thank you, Andrew

mdickin commented 6 years ago

Thank you for the quick turnaround, @andrewtelnov!