surveyjs / survey-creator

Scalable open-source survey software to generate dynamic JSON-driven forms within your JavaScript application. The form builder features a drag-and-drop UI, CSS Theme Editor, and GUI for conditional logic and form branching.
https://surveyjs.io/open-source
Other
896 stars 370 forks source link

Survey Creator - How to programmatically save JSON when editing via the editor? #1781

Open reubenporterjisc opened 3 years ago

reubenporterjisc commented 3 years ago

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

Question

What is the current behavior?

I have a react project using custom tabs and making use of surveyCreator.makeNewViewActive(tabName) to programmatically change the survey creator tabs (I am hiding the default ones with css). This works fine, but the issue I am having is that when editing the JSON in the JSON editor tab, those changes aren't actually being reflected when changing tabs again. I presume because I need to call my custom surveyCreator.saveSurveyFunc after the JSON has been edited, but I can't find a 'hook' or anything I can use to trigger a save on this action.

I have found and tried the code below but that's not working either.

surveyCreator.onActiveTabChanged.add(function (sender, opt) {
    if (sender.JSON !== surveyCreator.JSON) {
        saveSurvey(); // my custom save survey method
    }
});

What is the expected behavior?

When editing the JSON in the JSON editor tab I should be able to programmatically call my custom save survey function so that the new JSON is persisted across tabs.

novikov82 commented 2 years ago

We checked your scenario on our site https://surveyjs.io/create-survey It works ok for us. Can you share the exact steps to reproduce the issue?