Customize the Toolbar

Edit in →

Survey Creator's toolbar contains buttons that perform actions relevant to the active tab. For instance, the Designer tab allows users to undo and redo last operations, the Preview tab—change the device type and orientation, and the JSON Editor tab—import and export the survey JSON schema. This demo shows how to add a custom toolbar button that clears the survey on the design surface.

Configure a Toolbar Button

To configure a toolbar button, define an IAction object. Within it, you can set the button's unique ID, icon, title, and other parameters. You should also specify a function that this button will call and assign it to the action property. In this demo, the action function sets the Survey Creator's JSON property to an empty object, thus clearing the survey users configure.

import { Action } from "survey-core";

const clearSurveyAction = new Action({
    id: "clear-survey",
    title: "Clear Survey",
    showTitle: false,
    iconName: "icon-clear-24x24",
    action: () => {
        creator.JSON = {};
    }
});

Different tabs can have different toolbar buttons. To control the toolbar button visibility, use the IAction object's visible property. You can set it to a static Boolean value or to a ComputedUpdater instance if you need to calculate the property value dynamically. The ComputedUpdater constructor accepts a function that specifies the calculation rules. This function will be reevaluated each time a dependency property is changed. In this demo, the visible property depends on the Survey Creator's activeTab property:

const clearSurveyAction = new Action({
    // ...
    visible: new ComputedUpdater(() => creator.activeTab === "designer")
});

Add the Button to the Toolbar

Survey Creator includes two toolbars: top (for the desktop view) and bottom (for the mobile view). You can add your custom button to both or only one of the toolbars:

// Add a custom button to the top toolbar
creator.toolbar.actions.push(clearSurveyAction);

// Add a custom button to the bottom toolbar
creator.footerToolbar.actions.push(clearSurveyAction);

Open the Code tab to view the code example in full.

Your cookie settings

We use cookies on our site to make your browsing experience more convenient and personal. In some cases, they are essential to making the site work properly. By clicking "Accept All", you consent to the use of all cookies in accordance with our Terms of Use & Privacy Statement. However, you may visit "Cookie settings" to provide a controlled consent.

Your renewal subscription expires soon.

Since the license is perpetual, you will still have permanent access to the product versions released within the first 12 month of the original purchase date.

If you wish to continue receiving technical support from our Help Desk specialists and maintain access to the latest product updates, make sure to renew your subscription by clicking the "Renew" button below.

Your renewal subscription has expired.

Since the license is perpetual, you will still have permanent access to the product versions released within the first 12 month of the original purchase date.

If you wish to continue receiving technical support from our Help Desk specialists and maintain access to the latest product updates, make sure to renew your subscription by clicking the "Renew" button below.