Question T14105
Visible to All Users

Optimal way for updating questions Jsons while on a custom tab ( Surveyjs creator )

created a year ago (modified a year ago)

Hi,

I want your suggestion for the most optimal way to how I can update a question json, while on a seperate custom tab. For my business case, i have the following:
Clipboard-File-1.png

I want after entering the points, that the property point will be updated in each choice.

JavaScript
// it should go from this ... "elements": [ { "type": "radiogroup", "name": "question1", "choices": [ "Item 1", "Item 2", "Item 3" ] }, ... // to this "elements": [ { "type": "radiogroup", "name": "question1", "choices": [ {value: "Item 1" points: 3}, {value: "Item 2" points: 2}, {value: "Item 3" points: 5}, ] },

Note that i already have the property defined in the question and its choices.

I can use model.survey.getAllQuestions() and the navigate to the question and then use the functionsetPropertyValue() but its not a reactive optimal solution. I looked through the possible functions and couldn't find something that goes in the direction of for example question.overrideJson({}).

What do you suggest for my case?

Answers approved by surveyjs Support

created a year ago (modified a year ago)

Hello,
Thank you for contacting us.

To update survey element settings when a user switches away from a custom tab, subscribe to the deactivate function of a tab component and update settings of a creator.survey object.
Consider this demo:

JavaScript
const customTab = (creator) => ({ activate: () => {}, deactivate: () => { let survey = creator.survey; let checkbox = survey.getQuestionByName("question1"); checkbox.choices. //... Update choices' settings return true; } }); const customTabInstance = customTab(creator); creator.addPluginTab( "scoreeditor", customTabInstance, "Score Editor", "svc-tab-scoreeditor", 0 );

Please let me know if you have further questions.

For the record: an example on how to implement a custom Survey Creator tab is available at Generate Domain Model Code.