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
898 stars 373 forks source link

Theme Tab - Reset Behavior - Introduce an option to reset all user-defined settings and display a theme in its initial configuration #5302

Closed JaneSjs closed 6 months ago

JaneSjs commented 7 months ago

T16845 - When selecting another theme, the customized background and other properties remain between the themes https://surveyjs.answerdesk.io/internal/ticket/details/T16845


Usage scenario: When a user changes a theme, handle this and reset all user-defined settings and display a theme in its initial configuration.

So, we need the following APIs:

tsv2013 commented 6 months ago

Customers can use the following code:

    const options = {
        showThemeTab: true
    };
    const creator = new SurveyCreator.SurveyCreator(options);
    const themeTabPlugin = creator.themeEditor;
    let isResettingChanges = false;
    themeTabPlugin.onThemeSelected.add((s, o) => {
      if(!s.isModified) return;
      Survey.settings.confirmActionAsync("Do you want to reset all changes?", (confirm) => {
                if (confirm) {
                    if(isResettingChanges) return;
                    isResettingChanges = true;
                    s.model.setTheme({ themeName: s.model.themeName, isPanelless: s.model.themeMode === "lightweight", colorPalette: s.model.themePalette });
                    isResettingChanges = false;
                }
            });
    });

Here is the live example - https://plnkr.co/edit/BMTNURUoIZhZyEwJ