Add, remove, replace, save and load items in Question Toolbox.

Source code: Survey setup

var editorOptions = {questionTypes : ["text", "checkbox", "radiogroup", "dropdown"]};
var editor = new SurveyEditor.SurveyEditor("editorElement", editorOptions);
//Add all countries question into toolbox
editor.toolbox.addItem({
        name: "countries",
        isCopied: true,
        iconName: "icon-default",
        title: "All countries",
        json: { "type": "dropdown",  optionsCaption: "Select a country...", choicesByUrl: { url: "https://restcountries.eu/rest/v1/all"   } }
});

Question Toolbox API

Limit the default question types

Use questionTypes string array in the editorOptions parameter of Editor constructor. Only the given question types will appear in the Toolbox

var editorOptions = {questionTypes : ["text", "checkbox", "radiogroup", "dropdown"]};
var editor = new SurveyEditor.SurveyEditor("editorElement", editorOptions);

Question Toolbox functions

From version 0.12.0 a new editor.toolbox property has been introduced. It provides the full control under Question Toolbox.

  • Here is the list of available properties and functions:

  • jsonText – The string property. Allows to get and set all toolbox items as a string.

  • copiedJsonText – The string property. Allows to get and set copied questions as a string. End-user may add a queston into toolbox by clicking on 'Add to Toolbox' question menu item.
  • items – Returns the list of current toolbox items. Toolbox item properties are described below.
  • copiedItems – Returns the list of current copied toolbox items. End-user may add a queston into toolbox by clicking on 'Add to Toolbox' question menu item.
  • addItems(items[, clearAll]) – Add the list of toolbox items into toolbox. If an optional parameter clearAll is set to true, all previous items will be removed.
  • addCopiedItem(question – Add a question into Toolbox as a copied item.
  • addItem(item) – Add a new item into toolobx. If the item with the same name already exists, then replace it.
  • replaceItem(item) – Find an existing item by item.name and replace its properties. Return false if the item with the same name doesn't exist.
  • removeItem(name) – Find an existing item by name parameter and remove it.
  • clearItems() – Remove all items from the toolbox.
  • clearCopiedItems()
    • Remove all copied items from the toolbox.

Question Toolbox Item properties

{
    name: string;
    iconName: string;
    json: any;
    title: string;
    isCopied: boolean;
}
  • name – The required attribute. The unique item id. By default it is a question type.
  • iconName – The optional attribute. The icon name. The default value is 'icon-default'. It is 'icon-' + [question_type] for a standard Survey question.
  • json – The required attribute. A question is created based on this json. The json should has at least the 'type' string property. It used to create the correct question. All other properties are optional and you
  • title – The toolbox item title.
  • isCopied – true if the item is created by clicking on 'Add to Toolbox' question menu item.

results matching ""

    No results matching ""