Question T11585
Visible to All Users

Order of operations regarding dependsOn and onSetValue

created 2 years ago

I have two select lists, where on depends on the other. The issue I am having is the choices function on the 2nd property is being executed before the 1st property's onSetValue function has completed. I would think the dependsOn relationship would make sure the 1st property's value is set before running a dependancy's choices function.
Here are some relevant code snippets and a codesandbox link.
Thank you

JavaScript
Survey.Serializer.addProperty("survey", { name: "region", category: "Geo Location", categoryIndex: 1, onSetValue: async (obj, value, jsonConverter) => { console.log("region onSetValue START"); console.log("before sleep"); await sleep(2000); console.log("after sleep"); console.log("region onSetValue END"); return value; }, choices: ["Africa", "Americas", "Asia", "Europe", "Oceania"] }); Survey.Serializer.addProperty("survey", { name: "country", category: "Geo Location", dependsOn: ["region"], onSetValue: (obj, value, jsonConverter) => { console.log("country onSetValue START"); }, choices: function (obj, choicesCallback) { console.log("country choices fn called"); // shouldn't this be called after a dependsOn onSetValue? } });

Clipboard-File-1.png

I would expect "country choices fn called" between the two sleep log entries to be the last log entry.

(using async/await)
https://codesandbox.io/s/nervous-solomon-bp15gg?file=/src/index.js

(using promise chains)
https://codesandbox.io/s/festive-volhard-endvin?file=/src/index.js

Show previous comments (4)

    Hello Paul,
    Thank you for the update. After a Region property was set, call the updateDynamicProperties function to update a Country property editor:

    JavaScript
    let countryPropEditor = undefined; ... Survey.Serializer.addProperty("survey", { name: "region", category: "Geo Location", categoryIndex: 1, onSetValue: async (obj, value, jsonConverter) => { await sleep(2000); obj.setPropertyValue("region", value); if (countryPropEditor) { countryPropEditor.updateDynamicProperties(); } return value; }, choices: ["Africa", "Americas", "Asia", "Europe", "Oceania"] }); Survey.Serializer.addProperty("survey", { name: "country", category: "Geo Location", dependsOn: ["region"], onSetValue: (obj, value, jsonConverter) => { ... }, choices: function (obj, choicesCallback) { ... }, onPropertyEditorUpdate: (obj, editor) => { countryPropEditor = editor; } });

    The updated example: https://codesandbox.io/s/cocky-chatelet-5ulx2d?file=/src/index.js:338-1119.

    Please let me know if this does the trick.

    PC PC
    Paul Czywczynski 2 years ago

      Thanks Jane, we'll take it in-house and see if this works for us. -Paul

        Thank you for the update, Paul. Please feel free to share your results with us.

        Answers

        created 2 years ago

        Calling updateDynamicProperties() did solve our problem. Thank you. -Paul

          Comments (1)

            You're welcome, Paul. Please feel free to contact us if you have any questions or require further assistance.