Cart Buy Licenses Contact Support Login/Register
v 1.8.11
v 1.8.11
Overview Survey Creator Examples Docs Source Download

Modify Designer and Test Surveys

Use onSurveyInstanceCreated event to modify Surveys inside Creator


    .addProperty("question", {name:"popupDescription:text", category: "general", visibleIndex: 1});

            var creatorOptions = { };
            var creator = new SurveyCreator.SurveyCreator("creatorElement", creatorOptions);
            creator.showToolbox = "right";
            creator.showPropertyGrid = "right";
function createButtonForPopup(options, showPopup) {
    //Add a button;
    var btn = document.createElement("button");
    //Show button if popupDescription property is not empty = !options.question.popupDescription ? "hidden": "";
    btn.type = "button";
    btn.className = "btn btn-info btn-xs"; = "absolute"; = "20px"
    btn.innerHTML = "More Info";
    //Change button visibility on changing the property
    options.question.registerFunctionOnPropertyValueChanged("popupDescription", function(newValue){ = !newValue ? "hidden": "";
    if(showPopup) {
        var popupDescription = options.question.popupDescription;
        btn.onclick = function () {
    var header = options
    var span = document.createElement("span");
    span.innerHTML = "  ";
function renderQuestionInDesigner(survey, options) {
    createButtonForPopup(options, false);
function renderQuestionInTestSurvey(survey, options) {
    createButtonForPopup(options, true);
//Calls when creator needs to create a new survey instance.
//In most cases you need to check options.reason for "designer" and "test".
//Survey is created for designer survey or "Test Survey" tab.
//Several properties editors create survey as well. In this case the reason will be: "conditionEditor", "defaultValueEditor", "restfulEditor"
creator.onSurveyInstanceCreated.add(function(sender, options) {
    //If we are creating a surface for designer surface
    if(options.reason == "designer") {
    //If we are creating a surface for "Test Survey" tab
    if(options.reason == "test") {

//If there is no JSON, then call creator.JSON = {}; to re-create the designer survey and call onSurveyInstanceCreated event.
creator.JSON = {
    title: "Software developer survey.",
    pages: [
            title: "What operating system do you use?",
            questions: [
                    type: "checkbox",
                    name: "opSystem",
                    title: "OS",
                    hasOther: true,
                    isRequired: true,
                    popupDescription: "If you do not use any of the listed operating system, please select 'others' and type your operating system name.",
                    choices: ["Windows", "Linux", "Macintosh OSX"]
        }, {
            title: "What language(s) are you currently using?",
            questions: [
                    type: "checkbox",
                    name: "langs",
                    title: "Please select from the list",
                    popupDescription: "Select all programming languages you have been using for the last six months.",
                    colCount: 4,
                    isRequired: true,
                    choices: [
                        "Emacs Lisp",
        }, {
            title: "Please enter your name and e-mail",
            questions: [
                    type: "text",
                    name: "name",
                    title: "Name:",
                    popupDescription: "Please, type your name as 'Given Name' 'Family Name'."
                }, {
                    type: "text",
                    name: "email",
                    title: "Your e-mail",
                    popupDescription: "Please, make sure you do not misspell your e-mail."
<!DOCTYPE html>
<html lang="en">
    <title>Use onSurveyInstanceCreated event to modify Surveys inside Creator, Survey Creator Example</title>

<meta name="viewport" content="width=device-width" />
    <script src=""></script>
<script src="/DevBuilds/packages/survey-knockout/survey.ko.js"></script>
    <script src="" type="text/javascript" charset="utf-8"></script>
    <script src="" type="text/javascript" charset="utf-8"></script>
    <!-- Uncomment to enable Select2
    <script src=""></script>
    <link href="" rel="stylesheet" />
    <script src=""></script>
    <link href="/DevBuilds/build/survey-creator.css" type="text/css" rel="stylesheet" />
    <script src="/DevBuilds/build/survey-creator.js"></script>
    <link rel="stylesheet" href="">
    <link rel="stylesheet" href="./index.css">

    <div id="surveyContainer">
        <div id="creatorElement"></div>

<script type="text/javascript" src="./index.js"></script>